-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueHigh Priority
Milestone
Description
TypeScript Version: 3.6.2
Search Terms: type inference 3.6
Code
function asObservable(input: string | ObservableInput<string>): Observable<string> {
return typeof input === 'string' ? of(input) : from(input)
}
Expected behavior:
This function managed to compile correctly in 3.5 with RxJS 6.5.2
Actual behavior:
In 3.6, it fails with
Type 'Observable<unknown>' is not assignable to type 'Observable<string>'.
Type 'unknown' is not assignable to type 'string'.ts(2322)
the type of from()
does not get inferred anymore.
It is declared as
function from<O extends ObservableInput<any>>(input: O): Observable<ObservedValueOf<O>>
Specifically, the ObservedValueOf<T>
type fails now with ObservableInput<T>
:
type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never;
type ObservableInput<T> = SubscribableOrPromise<T> | ArrayLike<T> | Iterable<T>;
which worked before.
Related Issues: Filed at ReactiveX/rxjs#4992
benlesh and maxdeviant
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueHigh Priority