mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 02:15:10 -05:00
Narrow references within optional chains in for-in loops (#52059)
This commit is contained in:
committed by
GitHub
parent
4775381811
commit
40208a8ca7
@@ -26273,7 +26273,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return declaredType;
|
||||
}
|
||||
// for (const _ in ref) acts as a nonnull on ref
|
||||
if (isVariableDeclaration(node) && node.parent.parent.kind === SyntaxKind.ForInStatement && isMatchingReference(reference, node.parent.parent.expression)) {
|
||||
if (
|
||||
isVariableDeclaration(node) &&
|
||||
node.parent.parent.kind === SyntaxKind.ForInStatement &&
|
||||
(isMatchingReference(reference, node.parent.parent.expression) || optionalChainContainsReference(node.parent.parent.expression, reference))
|
||||
) {
|
||||
return getNonNullableTypeIfNeeded(finalizeEvolvingArrayType(getTypeFromFlowType(getTypeAtFlowNode(flow.antecedent))));
|
||||
}
|
||||
// Assignment doesn't affect reference
|
||||
|
||||
Reference in New Issue
Block a user