-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Use correct type for async refactoring diagnostics #26749
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
@@ -1178,11 +1188,17 @@ function [#|f|]() { | |||
} | |||
`); | |||
|
|||
_testConvertToAsyncFunction("convertToAsyncFunction_simpleFunctionExpression", ` | |||
const [#|foo|] = 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.
[#|foo|] [](start = 6, length = 8)
I realize you didn't change this, but that seems like a weird place for the squiggle. What if the function had a name?
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.
Tracked at #26801.
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.
@@ -42,7 +42,18 @@ namespace ts.codefix { | |||
|
|||
function convertToAsyncFunction(changes: textChanges.ChangeTracker, sourceFile: SourceFile, position: number, checker: TypeChecker, context: CodeFixContextBase): void { | |||
// get the function declaration - returns a promise | |||
const functionToConvert: FunctionLikeDeclaration = getContainingFunction(getTokenAtPosition(sourceFile, position)) as FunctionLikeDeclaration; | |||
const tokenAtPosition = getTokenAtPosition(sourceFile, position); | |||
let functionToConvert: FunctionLikeDeclaration; |
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.
let functionToConvert: FunctionLikeDeclaration | undefined;
, since getContainingFunction
may return undefined.
functionToConvert = tokenAtPosition.parent.initializer; | ||
} | ||
else { | ||
functionToConvert = getContainingFunction(getTokenAtPosition(sourceFile, position)) as FunctionLikeDeclaration; |
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.
Could use tryCast(..., isFunctionLikeDeclaration)
Fixes #26374, supersedes #26720 .
This PR aims to fix a few issues:
FunctionLikeDeclaration
. Here, we change it to inspect the signatures of the entire declaration. Attempting this without changing the checker used to a non-diagnostics-producing checker caused issues elsewhere, but this change fixed those issues.FunctionExpression
that is fixable is the direct child of aVariableDeclaration
, then it reports a diagnostic on the variable name. However, triggering the code fix on the variable name will not successfully perform the change. This PR specifically handles this scenario when performing the code fix.FunctionExpression
s, as well asFunctionLikeDeclaration
s without a return type annotation.