Skip to content

Commit 64bbf89

Browse files
author
Benjamin Lichtman
committed
Allow for undefined in type
1 parent f4765a6 commit 64bbf89

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/services/codefixes/convertToAsyncFunction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ namespace ts.codefix {
4343
function convertToAsyncFunction(changes: textChanges.ChangeTracker, sourceFile: SourceFile, position: number, checker: TypeChecker, context: CodeFixContextBase): void {
4444
// get the function declaration - returns a promise
4545
const tokenAtPosition = getTokenAtPosition(sourceFile, position);
46-
let functionToConvert: FunctionLikeDeclaration;
46+
let functionToConvert: FunctionLikeDeclaration | undefined;
4747

4848
// if the parent of a FunctionLikeDeclaration is a variable declaration, the convertToAsync diagnostic will be reported on the variable name
4949
if (isIdentifier(tokenAtPosition) && isVariableDeclaration(tokenAtPosition.parent) &&
5050
tokenAtPosition.parent.initializer && isFunctionLikeDeclaration(tokenAtPosition.parent.initializer)) {
5151
functionToConvert = tokenAtPosition.parent.initializer;
5252
}
5353
else {
54-
functionToConvert = getContainingFunction(getTokenAtPosition(sourceFile, position)) as FunctionLikeDeclaration;
54+
functionToConvert = tryCast(getContainingFunction(getTokenAtPosition(sourceFile, position)), isFunctionLikeDeclaration);
5555
}
5656

5757
if (!functionToConvert) {

0 commit comments

Comments
 (0)