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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/internal/operators/defaultIfEmpty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ import { operate } from '../Subscriber';
* specified `defaultValue` if the source Observable emits no items, or the
* values emitted by the source Observable.
*/


// To make things easier for (naughty) devs who use the
// `strictNullChecks: false` TypeScript compiler option, these
// overloads with explicit null and undefined values are included.

export function defaultIfEmpty<T, R extends null>(
defaultValue: R
): (source: Observable<T>) => Observable<T | null>;
export function defaultIfEmpty<T, R extends undefined>(
defaultValue: R
): (source: Observable<T>) => Observable<T | undefined>;

export function defaultIfEmpty<T, R>(defaultValue: R): OperatorFunction<T, T | R> {
return (source) =>
new Observable((destination) => {
Expand Down
Loading