-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix initializer widening #29192
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
Fix initializer widening #29192
Conversation
You didn't add a (full) test for #29189 - you set |
@@ -4919,7 +4919,7 @@ namespace ts { | |||
if (strictNullChecks && declaration.initializer && !(getFalsyFlags(checkDeclarationInitializer(declaration)) & TypeFlags.Undefined)) { | |||
type = getTypeWithFacts(type, TypeFacts.NEUndefined); | |||
} | |||
return declaration.initializer && !getContextualTypeForVariableLikeDeclaration(walkUpBindingElementsAndPatterns(declaration)) ? | |||
return declaration.initializer && !getEffectiveTypeAnnotationNode(walkUpBindingElementsAndPatterns(declaration)) ? |
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.
I'm not sure I think this is right to change. Outside of strict mode, I believe this is going to make a destructured variable with an undefined
initializer (with a contextual type) be any
instead of the correct contextual 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.
It's the right change (it basically just reverts the change that you had made). In classic checking mode this makes a variable of type string
as expected.
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.
Aight, ok then
I added |
Fixes #29189.