Skip to content

Commit

Permalink
chore: add test using comment snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Aug 15, 2019
1 parent b01ed04 commit 7017c0c
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions spec-dtslint/operators/filter-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { of } from 'rxjs';
import { filter } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
import { filter, map } from 'rxjs/operators';

it('should support a predicate', () => {
const o = of(1, 2, 3).pipe(filter(value => value < 3)); // $ExpectType Observable<number>
Expand Down Expand Up @@ -44,3 +44,16 @@ it('should support Boolean as a predicate', () => {
const p = of(1, null, undefined).pipe(filter(Boolean)); // $ExpectType Observable<number>
const q = of(null, undefined).pipe(filter(Boolean)); // $ExpectType Observable<never>
});

// I've not been able to effect a failing dtslint test for this situation and a
// conventional test won't fail because the TypeScript configuration isn't
// sufficiently strict:
// https://github.com/ReactiveX/rxjs/issues/4959#issuecomment-520629091
it('should support inference from a return type with Boolean as a predicate', () => {
interface I {
a: string | null;
}

const i$: Observable<I> = of();
const s$: Observable<string> = i$.pipe(map(i => i.a), filter(Boolean)); // $ExpectType Observable<string>
});

0 comments on commit 7017c0c

Please sign in to comment.