-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check if for-of iterated element types are disposable when using using
declarations
#60354
base: main
Are you sure you want to change the base?
Conversation
@typescript-bot test it (not that there are a major number of these in the wild, or even |
@typescript-bot test it |
@jakebailey Here are the results of running the user tests with tsc comparing Everything looks good! |
Hey @jakebailey, the results of running the DT tests are ready. Everything looks the same! |
@jakebailey Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
@jakebailey Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
@@ -44058,6 +44058,34 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |||
return type === autoType ? anyType : type === autoArrayType ? anyArrayType : type; | |||
} | |||
|
|||
function checkIfUsingDisposables(declaration: Declaration, type: Type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check would be handled by checkVariableLikeDeclaration
were it not for the fact that const initializer
in that function results in undefined
. It seems like we could fit this into that function as an else if
case for if (initializer)
to avoid repeating the same logic just for for..of
.
Something like:
let errorNode: Node | undefined;
let initializerType: Type | undefined;
if (initializer) {
const isJSObjectLiteralInitializer = ...;
if (!isJSObjectLiteralInitializer && node.parent.parent.kind !== SyntaxKind.ForInStatement) {
errorNode = initializer;
initializerType = checkExpressionCached(initializer);
checkTypeAssignableToAndOptionallyElaborate(initializerType, type, node, initializer, /*headMessage*/ undefined);
}
}
else if (node.parent.parent.kind === SyntaxKind.ForOfStatement) {
errorNode = (node.parent.parent as ForOfStatement).expression;
initializerType = checkRightHandSideOfForOf(node.parent.parent as ForOfStatement);
}
if (initializerType && errorNode) {
const blockScopeKind = getCombinedNodeFlagsCached(node) & NodeFlags.BlockScoped;
...
}
fixes #60348
cc @rbuckton