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
letx={then(cb: (x: string)=>any){cb('x');}};lety={then(cb: (x: Object)=>any){cb({});}};(Math.random()<.5 ? x : y).then((z)=>z);// z is string(Math.random()<.5 ? y : x).then((z)=>z);// z is Object
z should probably be string | Object in both cases.
Might be related, but if I have x: number in the second function above, the last lines fail with "Cannot invoke an expression whose type lacks a call signature", which is weird.
The text was updated successfully, but these errors were encountered:
In general you should never declare things as Object, it rarely does what you want (for example, string is assignable to Object). See #1809.
The primary issue is that Object is a supertype of string, and function parameters are bivariant (see the entry in the FAQ), so the type of x is assignable to y and the type of y is assignable to x, so we're basically just picking the first one here when resolving the type of expr ? x: y.
The related issue is because call signatures don't appear on union types unless the signatures are identical. See #5640
Example:
z
should probably bestring | Object
in both cases.Might be related, but if I have x: number in the second function above, the last lines fail with "Cannot invoke an expression whose type lacks a call signature", which is weird.
The text was updated successfully, but these errors were encountered: