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:
TypeScript not to complain about the typings.
Actual behavior:
In the f function, TypeScript says that problem may not have name because type Property 'name' does not exist on type 'a & c', but a and c are mutually exclusive types and therefore not possible. It also complains that problem may not have other because Property 'other' does not exist on type 'a & b', but due to the if/else, it's not possible for problem to be of type b, and in fact the only possible type for it is c.
Related Issues:#33101 looked like it might be related, can't quite tell.
The text was updated successfully, but these errors were encountered:
ReinAkane
changed the title
Regression in 3.6.3: Combination of union and intersection types with literal types not resolving specific types properly
Regression in 3.6: Combination of union and intersection types with literal types not resolving specific types properly
Sep 16, 2019
The type abc & (b | c) is creating a load of types that logically cannot exist because they contain a property that intersects disjoint types, for example a & c where the type of property type is 'a' & 'c'.
Prior to #31838 these propertys would remain as unreduced intersections that are incomparable to the discriminated property, and are therefore removed from the union type. Now they are reduced to never which is comparable and therefore not removed from the union --- this is why you have the new errors.
Tiny example:
constx: 'a'&'c'=4asany;if(x==='b'){// not comparable}consty: never=4asunknownasnever;if(y==='b'){// comparable}
Under 3.5 these two behave differently, now they behave the same.
It seems like the discriminant logic needs to change, perhaps to remove things that are incomparable or never, which makes sense because a never property can never match a discriminant property test at runtime.
TypeScript Version:
3.6.2
and3.6.3
Search Terms: union types, intersection types, literal types
Code
Expected behavior:
TypeScript not to complain about the typings.
Actual behavior:
In the
f
function, TypeScript says thatproblem
may not havename
because typeProperty 'name' does not exist on type 'a & c'
, buta
andc
are mutually exclusive types and therefore not possible. It also complains thatproblem
may not haveother
becauseProperty 'other' does not exist on type 'a & b'
, but due to the if/else, it's not possible forproblem
to be of typeb
, and in fact the only possible type for it isc
.Playground Link: Since the playground is still on 3.5.1, this issue is not reproducible there. Here's a link to the example I posted above in the playground (though it is passing): https://www.typescriptlang.org/play/#code/C4TwDgpgBAhlC8UDeAoK6qkgLigchjwBo0MATGYGXAZ2ACcBLAOwHMUBfFLaAIwWSl0PXHl7EhUZjAC2EWgxbsuPKAGMBqDJnDz8aidoD2wABYR6Cpm07ddsXhsRwAPlH5u1AbhQAzAK7MasCMRsxQvgAUYPRGvAA2EDK4MI5QAGRQkR7qAJS5gtqMvlkxcYkyAHSq8LX44gVa2hhqYTRGiZXxRqzRsQlJldJyuT7aHFAQ8TTQTc3qbR0QXT195YMm5vSjklxcQA
Related Issues: #33101 looked like it might be related, can't quite tell.
The text was updated successfully, but these errors were encountered: