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
Expected behavior:
Compiler complains that {} is not assignable to Fruit as the compiler sees T as a Fruit<apple> FIRST. Actual behavior:
Compiler finds best common type between Fruit<apple> and {} for T which ends up being {}. However, this means that the mapping function is not forced to return Fruit<apple>.
Additionally, if I specify mapping as:
mapping: ()=>T&{}
Then it works, and the mapping function must return a structure meeting the shape of Fruit<apple>.
If the appropriate generic types are explicitly provided, however, it also works. It just seems to try to best case guess T from all of its uses, and that best case almost always seems to be {} which means that this will always be broken...
Is this a problem related to the compiler picking the best common type/type inference for the generic, or am I wrong? (Also, sorry for opening so many issues recently, I'm building something new for work...)
The text was updated successfully, but these errors were encountered:
I feel like the only way to solve this is something like
leta: {}={b: 1};
Causing the error: { b: 1 } is not assignable to {} because b: number does not exist on {}
But I have a funny feeling that this is already "working as intended"...
TypeScript Version: 2.2.2 / nightly (2.2.0-dev.201xxxxx)
Code
Expected behavior:
Compiler complains that
{}
is not assignable to Fruit as the compiler seesT
as aFruit<apple>
FIRST.Actual behavior:
Compiler finds best common type between
Fruit<apple>
and{}
forT
which ends up being{}
. However, this means that the mapping function is not forced to returnFruit<apple>
.Additionally, if I specify mapping as:
Then it works, and the mapping function must return a structure meeting the shape of
Fruit<apple>
.If the appropriate generic types are explicitly provided, however, it also works. It just seems to try to best case guess
T
from all of its uses, and that best case almost always seems to be{}
which means that this will always be broken...Is this a problem related to the compiler picking the best common type/type inference for the generic, or am I wrong? (Also, sorry for opening so many issues recently, I'm building something new for work...)
The text was updated successfully, but these errors were encountered: