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
TypeScript Version: 3.6.2
Search Terms: type inference 3.6
Code
Expected behavior:
This function managed to compile correctly in 3.5 with RxJS 6.5.2
Actual behavior:
In 3.6, it fails with
the type of
from()does not get inferred anymore.It is declared as
Specifically, the
ObservedValueOf<T>type fails now withObservableInput<T>:which worked before.
Related Issues: Filed at ReactiveX/rxjs#4992