-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add missing arguments to typeToTypeNode. #38336
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,14 +39,20 @@ namespace ts.codefix { | |
}); | ||
|
||
function getInfo(sourceFile: SourceFile, checker: TypeChecker, pos: number): Info | undefined { | ||
const returnTypeNode = getReturnTypeNode(sourceFile, pos); | ||
if (isInJSFile(sourceFile)) { | ||
return undefined; | ||
} | ||
|
||
const token = getTokenAtPosition(sourceFile, pos); | ||
const func = findAncestor(token, isFunctionLikeDeclaration); | ||
const returnTypeNode = func?.type; | ||
if (!returnTypeNode) { | ||
return undefined; | ||
} | ||
|
||
const returnType = checker.getTypeFromTypeNode(returnTypeNode); | ||
const promisedType = checker.getAwaitedType(returnType) || checker.getVoidType(); | ||
const promisedTypeNode = checker.typeToTypeNode(promisedType); | ||
const promisedTypeNode = checker.typeToTypeNode(promisedType, /*enclosingDeclaration*/ func, /*flags*/ undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like CFA can't tell There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right - we can tell that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically if we removed the check though, we'd be in a bad situation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just observing that there seemed to be a potential improvement that could be made to CFA, not suggesting any changes to this code. |
||
if (promisedTypeNode) { | ||
return { returnTypeNode, returnType, promisedTypeNode, promisedType }; | ||
} | ||
|
@@ -55,16 +61,4 @@ namespace ts.codefix { | |
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, returnTypeNode: TypeNode, promisedTypeNode: TypeNode): void { | ||
changes.replaceNode(sourceFile, returnTypeNode, createTypeReferenceNode("Promise", [promisedTypeNode])); | ||
} | ||
|
||
function getReturnTypeNode(sourceFile: SourceFile, pos: number): TypeNode | undefined { | ||
if (isInJSFile(sourceFile)) { | ||
return undefined; | ||
} | ||
|
||
const token = getTokenAtPosition(sourceFile, pos); | ||
const parent = findAncestor(token, isFunctionLikeDeclaration); | ||
if (parent?.type) { | ||
return parent.type; | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.