Skip to content

Type declaration for ActivatedRoute.fragment doesn't declare possible null values #23894

@sliekens

Description

@sliekens

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Performance issue
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

The type declaration for ActivatedRoute.fragment declares that it will emit string instances and nothing else.

interface ActivatedRoute {
  fragment: Observable<string>
}

To my surprise, it emits null values for routes that don't have a fragment.

Expected behavior

I see three valid options here (in no particular order):

  1. emit '' instead of null for missing fragments
  2. don't emit at all for missing fragments
  3. just change the type declaration to Observable<string | null>

Minimal reproduction of the problem with instructions

https://angular-nullable-fragment.stackblitz.io

What is the motivation / use case for changing the behavior?

image

Environment


Angular version: 5.2.9


Browser:
- [x] Chrome (desktop) version 65
- [x] Firefox version 59


Others:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions