-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
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
the defaultIfEmpty
operator has erroneous & inconvenient typing
#6064
Comments
The types might not be correct, but I think I disagree with the expectations here. I think it should be: const a = of(true).pipe(defaultIfEmpty()); // $ExpectError (defaultIfEmpty should require an argument)
const b = of(undefined).pipe(defaultIfEmpty(undefined)); // $ExpectType Observable<undefined> (if we provide an undefined here, it should be undefined, not null) Further, the const a = EMPTY.pipe(defaultIfEmpty(123)); // $ExpectType Observable<number> This last one should work as you expect though: const d: Observable<boolean | null> = of(true).pipe(defaultIfEmpty(null)); // $ExpectType Observable<boolean | null> |
i dont think we disagree at all, if you read my last point under "additional context". but this would be a breaking change. the typing issues should be fixed asap to reflect the current reality, which i showed in the "expected behavior" section. for the next major i 100% agree with your proposals. edit: so this ticket is really only about fixing incorrect types. cleaning up the API & behavior would be a change request, which i can create a separate ticket for, if you like. |
…ument BREAKING CHANGE: `defaultIfEmpty` requires a value be passed. Will no longer convert `undefined` to `null` for no good reason. Resolves ReactiveX#6064
@backbone87 thanks for bring this to my attention. As it turns out, it was related to a rash of edge case bugs related to the composition of this operator: #6070 |
so #6070 goes into ^7 since breaking. can we fix the typings for ^6, should i give it a go? |
…ument BREAKING CHANGE: `defaultIfEmpty` requires a value be passed. Will no longer convert `undefined` to `null` for no good reason. Resolves #6064
Bug Report
Current Behavior
Expected behavior
Reproduction
Creating a repo with stackblitz or codesandbox didnt work as changing the TS version/config doesnt seem to affect their editor.
You an just take the code above and drop it into any TS ^4 strict project.
Environment
Possible Solution
change the type signatur of
defaultIfEmpty
to something like:<T, R>(value?: R) => OperatorFunction<T, T | R>
Additional context/Screenshots
I would also deprecate the default of value and require an argument:
<T, R>(value: R) => OperatorFunction<T, T | R>
this is because
defaultIfEmpty(undefined)
results actually in the same asdefaultIfEmpty(null)
, which is unexpected.The text was updated successfully, but these errors were encountered: