You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
letid=<T>(b: Test<T>)=>0;typeTest<T>=(b: T)=>any;lett=(b: {a: number})=>0;letu=<U>(b: {a: number})=>0;id(t);id(u);// Fails on `u`letv: Test<{a: number}>=u;// But this passesletid2=<T>(b: Test2<T>)=>0;typeTest2<T>=<U>(b: T)=>any;id2(t);id2(u);// Now it passes
Expected behavior: I don't even know what the intent here is
Actual behavior: As noted in code comments
Here's the error I get on u:
Argument of type '<U>(b: { a: number; }) => number' is not assignable to parameter of type 'Test<{}>'.
Types of parameters 'b' and 'b' are incompatible.
Type '{}' is not assignable to type '{ a: number; }'.
Property 'a' is missing in type '{}'.
I ran into this problem while writing some complex code, after reducing and reducing forever, I managed to track it down to this very abstract example. My apologies if it's a bit hard to follow. I feel like this is a bug? At the very least it's very unexpected behavior and the error messages surrounding this issue tend to be very cryptic.
The text was updated successfully, but these errors were encountered:
declarefunctionid<T>(x: (b: T)=>any): number;declarefunctiontest<U>(b: string): number;id(test);// Error because T inferred as {}
We fail to infer string for T because, upon seeing an argument of a type that has a generic signature (in this case <U>(b: string) => number) being passed to a parameter of a type with a non-generic signature (in this case (b: T) => any), we assume that the argument function uses its type parameter (in this case U) in a parameter position. Therefore, we first need to infer for U, and to do that we need to fix any inferences we have made for T so that we can infer to the type involving U. However, the type doesn't actually use U, so it ends up being a fruitless exercise that just causes T to become fixed with no inferences. Hence the {}.
So, it's behaving as intended and is effectively a design limitation of our inference algorithm.
I would really love to eventually get that one, as it's basically required for lifted type constructors, which is where I ran into this bug twice now. There's a lot of situations where you have something like
<U>(a: T)=>Array<T>
The only way to properly type anything that passes through such lifting functions is by inferring the return type, but this issue is blocking it. I thought I found a workaround, but apparently, I just moved the issue elsewhere :)
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
TypeScript Version: 2.9.0-dev.20180420
Code
Expected behavior: I don't even know what the intent here is
Actual behavior: As noted in code comments
Here's the error I get on
u
:I ran into this problem while writing some complex code, after reducing and reducing forever, I managed to track it down to this very abstract example. My apologies if it's a bit hard to follow. I feel like this is a bug? At the very least it's very unexpected behavior and the error messages surrounding this issue tend to be very cryptic.
The text was updated successfully, but these errors were encountered: