Skip to content

RxJS type inference fails in 3.6.2 #33131

Description

TypeScript Version: 3.6.2

Search Terms: type inference 3.6

Code

functionasObservable(input: string|ObservableInput<string>): Observable<string>{returntypeofinput==='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

functionfrom<OextendsObservableInput<any>>(input: O): Observable<ObservedValueOf<O>>

Specifically, the ObservedValueOf<T> type fails now with ObservableInput<T>:

typeObservedValueOf<O>=OextendsObservableInput<infer T> ? T : never;typeObservableInput<T>=SubscribableOrPromise<T>|ArrayLike<T>|Iterable<T>;

which worked before.

Related Issues: Filed at ReactiveX/rxjs#4992

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions