Skip to content

Commit

Permalink
chore: fix iif typings to infer never (#5176)
Browse files Browse the repository at this point in the history
* chore(typings): fix iif observable typings for optional parameters (#4494)

* test(dtslint): add dtslint test for iif observable static function (#4093)

* chore: remove unnecessary signature

* chore: fix dtslint expectations

Closes #4494

* chore: empty commit to kick CI
  • Loading branch information
cartant authored and benlesh committed Dec 11, 2019
1 parent cbc7721 commit 2c2f68c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions spec-dtslint/observables/iif-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { iif, of } from 'rxjs';

it('should accept function as first parameter', () => {
const a = iif(() => false); // $ExpectType Observable<never>
});

it('should infer correctly with 2 parameters', () => {
const a = iif(() => false, of(1)); // $ExpectType Observable<number>
});

it('should infer correctly with 3 parameters', () => {
const a = iif(() => false, of(1), of(2)); // $ExpectType Observable<number>
});

it('should infer correctly with 3 parameters of different types', () => {
const a = iif(() => false, of(1), of('a')); // $ExpectType Observable<string | number>
});
4 changes: 2 additions & 2 deletions src/internal/observable/iif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ import { SubscribableOrPromise } from '../types';
* @static true
* @name iif
* @owner Observable
*/
export function iif<T, F>(
*/
export function iif<T = never, F = never>(
condition: () => boolean,
trueResult: SubscribableOrPromise<T> = EMPTY,
falseResult: SubscribableOrPromise<F> = EMPTY
Expand Down

0 comments on commit 2c2f68c

Please sign in to comment.