Skip to content
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

Fixed defaultIfEmpty incorrect type with strictNullChecks off #7287

Closed

Conversation

shessafridi
Copy link

Description:

defaultIfEmpty(null) or defaultIfEmpty(undefined) always returns the observable of type Observable<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>

This PR fixes the issue by adding explicit overloads for null and undefined

Related issue (if exists): #7280

@shessafridi
Copy link
Author

ping @benlesh

@shessafridi
Copy link
Author

ping @jakovljevic-mladen

@conblem
Copy link

conblem commented Apr 11, 2024

What happenened to this pr?

@benlesh
Copy link
Member

benlesh commented May 3, 2024

Honestly, I remember glancing at it, and thinking about it, but deciding (at the time) that it doesn't seem like something we want to support. If people want to turn off strict settings in TypeScript, that's their business. I left it here because I wasn't totally convinced I was correct, but every time I revisited it, I had the same thought. That it wasn't the right thing to do.

Sorry @shessafridi I should have more openly written out my thoughts. Thank you for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants