File tree 1 file changed +12
-3
lines changed
1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -29342,9 +29342,17 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
29342
29342
// We first attempt to filter the current type, narrowing constituents as appropriate and removing
29343
29343
// constituents that are unrelated to the candidate.
29344
29344
const isRelated = checkDerived ? isTypeDerivedFrom : isTypeSubtypeOf;
29345
+ const keyPropertyName = type.flags & TypeFlags.Union ? getKeyPropertyName(type as UnionType) : undefined;
29346
+ const discriminantMatchingType = keyPropertyName ?
29347
+ mapType(candidate, c => {
29348
+ const discriminant = keyPropertyName && getTypeOfPropertyOfType(c, keyPropertyName);
29349
+ return (discriminant && getConstituentTypeForKeyType(type as UnionType, discriminant)) ?? neverType;
29350
+ }) :
29351
+ neverType;
29345
29352
let matchedCandidates: Type[] = [];
29346
- let narrowedType = mapType(type, t =>
29347
- mapType(
29353
+ let narrowedType = mapType(
29354
+ !(discriminantMatchingType.flags & TypeFlags.Never) ? discriminantMatchingType : type,
29355
+ t => mapType(
29348
29356
candidate,
29349
29357
c => {
29350
29358
const directlyRelated = checkDerived ?
@@ -29355,7 +29363,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
29355
29363
}
29356
29364
return directlyRelated;
29357
29365
},
29358
- ));
29366
+ ),
29367
+ );
29359
29368
if (matchedCandidates.length !== countTypes(candidate)) {
29360
29369
narrowedType = getUnionType([
29361
29370
narrowedType,
You can’t perform that action at this time.
0 commit comments