-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fixes #17080 #21328
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
Fixes #17080 #21328
Conversation
Changes are in src/compiler.checker.ts only The second arguments to the function "removeOptionalityFromDeclaredType" has been changed from "getRootDeclaration(declaration)" to "declaration".
microsoft#17080 Added testcases from the Github bugreport (all working as intended now). Signed CLA.
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’ll approve and merge after I understand why getRootDeclaration was added in the first place, and after a couple of minor fixes.
pull_request_template.md
Outdated
@@ -2,15 +2,16 @@ | |||
Thank you for submitting a pull request! |
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 don’t think this file was supposed to be part of the PR.
useBar(bar); | ||
} | ||
|
||
function useBar(bar: number) { |
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.
You can just declare function useBar(bar: number): void;
@@ -13046,7 +13046,7 @@ namespace ts { | |||
node.parent.kind === SyntaxKind.NonNullExpression || | |||
declaration.kind === SyntaxKind.VariableDeclaration && (<VariableDeclaration>declaration).exclamationToken || | |||
declaration.flags & NodeFlags.Ambient; | |||
const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, getRootDeclaration(declaration) as VariableLikeDeclaration) : type) : | |||
const initialType = assumeInitialized ? (isParameter ? removeOptionalityFromDeclaredType(type, declaration as VariableLikeDeclaration) : 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.
Any idea why getRootDeclaration was here? Was this copied from some other source that would also have an erroneous call to it?
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 tracked it back to #14498, which switched to the current narrowing approach that this PR fixes. From my memory of it, I think that I inserted getRootDeclaration
during development, then forgot to remove it after changing other parts of the code. Then none of our test cases caught the bug.
Approved after the two small fixes requested. |
Fixed the two requested changes. 1) Deleting the file "pull_request_template.md" 2) Declaring functions in tests, instead of defining
pull_request_template.md
Outdated
@@ -1,16 +0,0 @@ | |||
<!-- |
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.
Now this file is deleted, but shouldn't be.
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.
Sry about that... :-(
Readded untouched pull_request_template.md
Thanks @Lazarus535 ! Our test coverage was pretty bad here and is now much better. |
Changes are in src/compiler.checker.ts only
The second arguments to the function "removeOptionalityFromDeclaredType" has been changed from "getRootDeclaration(declaration)" to "declaration".
Fixes #