We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defaultIfEmpty(null) or defaultIfEmpty(undefined) always returns the observable of type Observable<any>
defaultIfEmpty(null)
defaultIfEmpty(undefined)
Observable<any>
When strictNullChecks is off null type is ignored so it should just return the type of the source observable as it is.
Expected behaviour in strictNullChecks: false
strictNullChecks: false
const test$ = of(1).pipe(defaultIfEmpty(null)); // Observable<number>
Instead we get
const test$ = of(1).pipe(defaultIfEmpty(null)); // Observable<any>
const test = of(1).pipe(defaultIfEmpty(null));
No response
7.8.1
"typescript": "~5.0.4", "rxjs": "^7.8.1"
I am currently using a custom wrapper operator built over defaultIfEmpty to fix the issue, here is the code for it.
defaultIfEmpty
import { defaultIfEmpty, Observable } from 'rxjs'; export function defaultIfEmptyFixed<T, R extends null>( defaultValue: R ): (source: Observable<T>) => Observable<T | null>; export function defaultIfEmptyFixed<T, R extends undefined>( defaultValue: R ): (source: Observable<T>) => Observable<T | undefined>; export function defaultIfEmptyFixed<T, R>( defaultValue: R ): (source: Observable<T>) => Observable<T | R> { return (input: Observable<T>) => input.pipe(defaultIfEmpty<T, R>(defaultValue)); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Describe the bug
defaultIfEmpty(null)
ordefaultIfEmpty(undefined)
always returns the observable of typeObservable<any>
Expected behavior
When strictNullChecks is off null type is ignored so it should just return the type of the source observable as it is.
Expected behaviour in
strictNullChecks: false
const test$ = of(1).pipe(defaultIfEmpty(null)); // Observable<number>
Instead we get
const test$ = of(1).pipe(defaultIfEmpty(null)); // Observable<any>
Reproduction code
Reproduction URL
No response
Version
7.8.1
Environment
"typescript": "~5.0.4",
"rxjs": "^7.8.1"
Additional context
I am currently using a custom wrapper operator built over
defaultIfEmpty
to fix the issue, here is the code for it.The text was updated successfully, but these errors were encountered: