-
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
test(dtslint): add dtslint test on count operator (#4093) #4139
Conversation
spec-dtslint/operators/count-spec.ts
Outdated
import { count } from 'rxjs/operators'; | ||
|
||
it('should always infer number', () => { | ||
const o = of(1, 2, 3).pipe(count(x => x > 1)); // $ExpectType Observable<number> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should also test the predicate overloads.
predicate: (value: T, index: number, source: Observable<T>)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added few more tests around the predicate overloads types.
Please let me know if they are of a good value.
Thanks
spec-dtslint/operators/count-spec.ts
Outdated
}); | ||
|
||
it('should expect function parameter', () => { | ||
const o = of(1, 2, 3).pipe(count(9)); // $ExpectError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also test if the value is the same type as the source.
For example
const o = of(1, 2, 3).pipe(count((value: string) => value !== ''); // $ExpectError
e81920e
to
3796334
Compare
spec-dtslint/operators/count-spec.ts
Outdated
import { count, buffer } from 'rxjs/operators'; | ||
|
||
it('should always infer number', () => { | ||
const o = of(1, 2, 3).pipe(count(x => x > 1)); // $ExpectType Observable<number> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With count
, the return type of the piped observable will always be Observable<number>
, so I think that for at least one of the tests, the source observable type should be something other than number
- to make sure that the output type comes from the count
operator and not the source. E.g.:
const o = of('1', '2', '3').pipe(count(x => x !== '1')); // $ExpectType Observable<number>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cartant I have added another row to both number or string will always return number
3796334
to
8bf3c77
Compare
8bf3c77
to
6267245
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description: Add count dtslint test
Related issue (if exists): #4093