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
This is almost certainly due to the empty-intersection-elimination PR #18438. I'm constructing a smaller repro that's easier to understand so I can see whether the new behaviour is correct.
The underlying error is that strictKeys has a circular constraint, which is illegal and doesn't have well-defined semantics. However, this is not reported and the compiler does its best to produce some kind of type from instantiations of strictType.
There seem to be other constructions that don't report circular constraints, such as index signatures.
Impossible intersections break index access types
In 2.5.2 and earlier, the first error is hidden by another limitation of the compiler: indexing a type with a union that includes impossible intersections just produces any:
#18438 now removes impossible intersections from unions, making bad now have the same type as good.
It also means that which means that strictKeys<obj2[k], key2[k]> was previously strictKeys<any, key2[k]>. Now it's strictKeys<{ a1, a2 } | { b1, b2}, key2[k]>. This means that the first error is now visible.
Improvements to impossible-intersection-removal
Some recent change further improved impossible intersection removal. If you build from master, you'll see errors for both T1 and T2. That's because obj1[k] is now simplified to 'a' | 'b' just like obj2[k] is simplified to 'a' | 'b' | 'c'.
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
Activity
xiaocaibird commentedon Oct 3, 2017
it's working in typescript@2.5.2 Andy (Andrewkraft) (@Andy-MS)
xiaocaibird commentedon Oct 3, 2017
Andy (Andrewkraft) (@Andy-MS)
xiaocaibird commentedon Oct 3, 2017
when i delete 'c' from 'obj2', T2 is ok
Andy (Andrewkraft) (@Andy-MS)
sandersn commentedon Oct 3, 2017
This is almost certainly due to the empty-intersection-elimination PR #18438. I'm constructing a smaller repro that's easier to understand so I can see whether the new behaviour is correct.
sandersn commentedon Oct 3, 2017
Briefly,
strictKeysis wrong. Here's a couple of correct implementations. I'll explain our investigation below:Circular constraints not reported
The underlying error is that strictKeys has a circular constraint, which is illegal and doesn't have well-defined semantics. However, this is not reported and the compiler does its best to produce some kind of type from instantiations of strictType.
There seem to be other constructions that don't report circular constraints, such as index signatures.
Impossible intersections break index access types
In 2.5.2 and earlier, the first error is hidden by another limitation of the compiler: indexing a type with a union that includes impossible intersections just produces any:
#18438 now removes impossible intersections from unions, making
badnow have the same type asgood.It also means that which means that
strictKeys<obj2[k], key2[k]>was previouslystrictKeys<any, key2[k]>. Now it'sstrictKeys<{ a1, a2 } | { b1, b2}, key2[k]>. This means that the first error is now visible.Improvements to impossible-intersection-removal
Some recent change further improved impossible intersection removal. If you build from master, you'll see errors for both
T1andT2. That's becauseobj1[k]is now simplified to'a' | 'b'just likeobj2[k]is simplified to'a' | 'b' | 'c'.xiaocaibird commentedon Oct 4, 2017
Nathan Shively-Sanders (@sandersn) Oh thank you for your answer, I'm still learning type system of typescript.
mhegazy commentedon Oct 19, 2017
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.