File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29342,11 +29342,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2934229342 // We first attempt to filter the current type, narrowing constituents as appropriate and removing
2934329343 // constituents that are unrelated to the candidate.
2934429344 const isRelated = checkDerived ? isTypeDerivedFrom : isTypeSubtypeOf;
29345+ const keyPropertyName = type.flags & TypeFlags.Union ? getKeyPropertyName(type as UnionType) : undefined;
2934529346 let matchedCandidates: Type[] = [];
2934629347 let narrowedType = mapType(type, t =>
2934729348 mapType(
2934829349 candidate,
2934929350 c => {
29351+ if (keyPropertyName) {
29352+ // If a discriminant property is available, use only matching constituents to reduce the type.
29353+ const discriminant = keyPropertyName && getTypeOfPropertyOfType(c, keyPropertyName);
29354+ if (!discriminant || getConstituentTypeForKeyType(type as UnionType, discriminant) !== t) {
29355+ return neverType;
29356+ }
29357+ }
2935029358 // For each constituent t in the current type, if t and and c are directly related, pick the most
2935129359 // specific of the two. When t and c are related in both directions, we prefer c for type predicates
2935229360 // because that is the asserted type, but t for `instanceof` because generics aren't reflected in
You can’t perform that action at this time.
0 commit comments