-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add related diagnostic to "used before defined" if type is a function that returns a union with undefined #33171
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
Conversation
tests/baselines/reference/functionTypeReturnsUnionWithUndefinedWithStrictNullChecks.errors.txt
Show resolved
Hide resolved
src/compiler/checker.ts
Outdated
const parenedFuncType = getMutableClone(funcTypeNode); | ||
// Highlight to the end of the second to last constituent of the union | ||
parenedFuncType.end = unionTypes[unionTypes.length - 2].end; | ||
addRelatedInfo(diag, createDiagnosticForNode(parenedFuncType, Diagnostics.Did_you_mean_to_parenthesize_this_function_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.
Instead of cloning the node, I believe we should have another function that takes a start/end (createFileDiagnostic
?). To get the correct start (that ignores whitespace), there should be a skipTrivia
function.
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 unclear on what "trivia" is exactly.
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.
Trivia is generally comments - https://github.com/microsoft/TypeScript/wiki/Architectural-Overview#terminology
Will be picking back up on this PR and resolving the comments this week 👍 |
@OzairP are you going to pick back up on this PR? |
@m-henderson yes I am picking back up on it this weekend. |
Alright, this looks good to me - thanks @OzairP |
…function that returns a union with undefined (microsoft#33171)" (microsoft#35751) This reverts commit be960fa.
Fixes #32846
This PR conforms to the requirements in #32846 with one distinct difference.
Instead of signaling a distinct error, the error is added as related info to TS2454 (used before defined).
I came to this conclusion after writing this test case.
Here it may be so that they meant to parenthesize
() => void
but considering there may be many lines of code between the type alias and the variable declaration, the origin of the error becomes unclear.However if the diagnostic is added as related information the origin of the error becomes clear if it was intentional or unintentional.
If is not agreed that this diagnostic should be related information I am good for changing it. 👍