mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-07 12:25:09 -05:00
Grab the left type when narrowing by in operator lazily (#54795)
This commit is contained in:
committed by
GitHub
parent
ef0422b40f
commit
adf5e8443b
@@ -27175,14 +27175,16 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return narrowTypeByPrivateIdentifierInInExpression(type, expr, assumeTrue);
|
||||
}
|
||||
const target = getReferenceCandidate(expr.right);
|
||||
const leftType = getTypeOfExpression(expr.left);
|
||||
if (leftType.flags & TypeFlags.StringOrNumberLiteralOrUnique) {
|
||||
if (containsMissingType(type) && isAccessExpression(reference) && isMatchingReference(reference.expression, target) &&
|
||||
getAccessedPropertyName(reference) === getPropertyNameFromType(leftType as StringLiteralType | NumberLiteralType | UniqueESSymbolType)) {
|
||||
if (containsMissingType(type) && isAccessExpression(reference) && isMatchingReference(reference.expression, target)) {
|
||||
const leftType = getTypeOfExpression(expr.left);
|
||||
if (isTypeUsableAsPropertyName(leftType) && getAccessedPropertyName(reference) === getPropertyNameFromType(leftType)) {
|
||||
return getTypeWithFacts(type, assumeTrue ? TypeFacts.NEUndefined : TypeFacts.EQUndefined);
|
||||
}
|
||||
if (isMatchingReference(reference, target)) {
|
||||
return narrowTypeByInKeyword(type, leftType as StringLiteralType | NumberLiteralType | UniqueESSymbolType, assumeTrue);
|
||||
}
|
||||
if (isMatchingReference(reference, target)) {
|
||||
const leftType = getTypeOfExpression(expr.left);
|
||||
if (isTypeUsableAsPropertyName(leftType)) {
|
||||
return narrowTypeByInKeyword(type, leftType, assumeTrue);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user