-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Partial type inference failures with tagged union types #13754
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
Comments
It seems the problem comes from Smaller reproduction. declare function f(process: A | B): void;
type A = {
call(p: number): void
brand: number
}
type B = {
call(p: string): void
brand: string
}
f({
brand: 123,
call(n) {} // any
}) To my best knowledge, compiler will not narrow union type in argument inference, for now. A better alternative is using overloading. declare function f<P, R, S>(process: Supervisor.Process<P, R, S>): void;
declare function f<P, R, S>(process: Supervisor.Process.Call<P, R, S>): void; |
Oh it is a nice workaround! Thanks! |
I found a problem in this workaround. The overload should be: declare function f<P, R, S>(process: Supervisor.Process.Call<P, R, S>): void;
declare function f<P, R, S>(process: Supervisor.Process<P, R, S>): void; details: #13780 |
|
The contextual type for the function is the union type. the union type property does not have a call signature because they are not identical. see #7294 for more details. |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
Probably an example without the type guard of #13454.
TypeScript Version: master
Code
Expected behavior:
ok
Actual behavior:
The text was updated successfully, but these errors were encountered: