-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
RxJS type inference fails in 3.6.2 #33131
Comments
Related to #33125? |
Yeah, this one is really not good for RxJS and will break a lot of people. This comment is a solid illustration of why |
Not using RxJS, but I can confirm that a number of spots in our codebase where type inference was working before (in 3.4.1) broke after upgrading to 3.6.2. |
There are apparently some type-inference issues in TypeScript 3.6: microsoft/TypeScript#33131
So, this is my minimal repro: declare function of<T>(a: T): Observable<T>;
declare function from<O extends ObservableInput<any>>(input: O): Observable<ObservedValueOf<O>>;
type ObservedValueOf<O> = O extends ObservableInput<infer T> ? T : never;
interface Subscribable<T> {
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void;
}
type ObservableInput<T> = Subscribable<T> | Subscribable<never>;
declare class Observable<T> implements Subscribable<T> {
subscribe(next?: (value: T) => void, error?: (error: any) => void, complete?: () => void): void;
}
function asObservable(input: string | ObservableInput<string>): Observable<string> {
return typeof input === 'string' ? of(input) : from(input)
} The |
Haaaaaaaaaaaaaaaaaaaaaah the issue is with our new inference matching code. We try to infer from |
This actually makes perfect sense to me. Since I guess it's not too nice if it breaks real-world code though. 😉 |
While the above is true, I did subsequently realize it probably makes the internal union order observable in unexpected ways, which isn't too nice from a theoretical basis either*. So 👍 to #33154 from me. * Always remember to put down the hood when done working on the car lest people start hot-wiring stuff after you walk away. 🚗 😛 |
Here's another one that is broken: import { defer, of } from 'rxjs';
const a$ = defer(() => of(1)); // $ExpectType Observable<number> In 3.6, this is now |
Can you all try out |
I've seen some cases where VSCode has chosen to put something like :
instead of
I've seen this cause similar problems with inference - that sometimes work and sometimes don't. So check your imports aren't absolute. (And yes this is a custom operator) |
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
The text was updated successfully, but these errors were encountered: