-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Strict function check failure due to union type with matching parameters in the unioned interfaces #20714
Comments
@ahejlsberg can you elucidate? Simplified repro with unique names: interface IBar<B> {
myParam: B | "";
}
interface IFoo<F> {
myParam: F;
}
var helper: <A>() => (IFoo<A> | IBar<A>);
helper = <T>(): (IFoo<T> | IBar<T>) => {
return <any>null;
}; |
Seems similar to #20702 |
Here's what happens: In order to check the assignment to We could potentially consider being more selective in inference between union types by attempting to pairwise match types in the source and target to avoid "cross contamination", but it gets complicated pretty quickly. |
My original issue had the two props being functions that returned different things: It sounds like the "right" solution would be along the lines that you mention: break up the union and infer (and compare) them all pairwise. Is this something that could reasonably be done or is it too destabilizing and should be saved as part of some bigger refactor? |
This works as expected now |
TypeScript Version: 2.7.0-dev.20171214
Code
Expected behavior:
Compiling the above code with "tsc .ts -strictFunctionTypes" should succeed.
Actual behavior:
Somehow wires get crossed and we get this error:
Note the unexplained switch from
IBar<A>
toIBar<ResultOrMissing<A>>
.The text was updated successfully, but these errors were encountered: