-
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
fix(startWith): add empty signature #4034
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { of, asyncScheduler } from 'rxjs'; | ||
import { startWith } from 'rxjs/operators'; | ||
|
||
it('should infer correctly with one value', () => { | ||
const o = of(1, 2, 3).pipe(startWith(4)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should infer correctly with multiple values', () => { | ||
const o = of(1, 2, 3).pipe(startWith(4, 5, 6)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should infer correctly with no value', () => { | ||
const o = of(1, 2, 3).pipe(startWith()); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should infer correctly with a value and a scheduler', () => { | ||
const o = of(1, 2, 3).pipe(startWith(5, asyncScheduler)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should infer correctly with only a scheduler', () => { | ||
const o = of(1, 2, 3).pipe(startWith(asyncScheduler)); // $ExpectType Observable<number> | ||
}); | ||
|
||
it('should enforce types with one value', () => { | ||
const o = of(1, 2, 3).pipe(startWith('foo')); // $ExpectError | ||
}); | ||
|
||
it('should enforce types with multiple value', () => { | ||
const o = of(1, 2, 3).pipe(startWith(4, 'foo')); // $ExpectError | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, although this might not be possible in this case without the overloads getting out of control. |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import { isScheduler } from '../util/isScheduler'; | |
import { MonoTypeOperatorFunction, SchedulerLike } from '../types'; | ||
|
||
/* tslint:disable:max-line-length */ | ||
export function startWith<T>(scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we're going to need to differentiate between what's being passed into the export function startWith<T, R>(...args: R[], scheduler?: SchedulerLike): OperatorFunction<T, T|R>; There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAICT this won't be work because it's only possible to define a rest parameter as the last argument in a function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @timdeschryver You'd need to use a union type as the rest parameter type. Have a look at There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed that there is already a rest parameters signature. I think the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I agree that's what I have right now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I guess if |
||
export function startWith<T>(v1: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>; | ||
export function startWith<T>(v1: T, v2: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction<T>; | ||
export function startWith<T>(v1: T, v2: T, v3: T, scheduler?: SchedulerLike): MonoTypeOperatorFunction<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.
I feel like this should be
// $ExpectType Observable<number|string>