Skip to content

Commit

Permalink
fix(46466): add missing async keyword before type parameters (microso…
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk authored and mprobst committed Jan 10, 2022
1 parent 0c0fb69 commit 19be4c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/services/codefixes/fixAwaitInSyncFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ namespace ts.codefix {
insertBefore = findChildOfKind(containingFunction, SyntaxKind.FunctionKeyword, sourceFile);
break;
case SyntaxKind.ArrowFunction:
insertBefore = findChildOfKind(containingFunction, SyntaxKind.OpenParenToken, sourceFile) || first(containingFunction.parameters);
const kind = containingFunction.typeParameters ? SyntaxKind.LessThanToken : SyntaxKind.OpenParenToken;
insertBefore = findChildOfKind(containingFunction, kind, sourceFile) || first(containingFunction.parameters);
break;
default:
return;
Expand Down
16 changes: 16 additions & 0 deletions tests/cases/fourslash/codeFixAddMissingAsync3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// <reference path="fourslash.ts" />

////const foo = <T>(x: T): string => {
//// await new Promise(resolve => resolve(true));
//// return "";
////}

verify.codeFix({
description: ts.Diagnostics.Add_async_modifier_to_containing_function.message,
index: 0,
newFileContent:
`const foo = async <T>(x: T): Promise<string> => {
await new Promise(resolve => resolve(true));
return "";
}`
});

0 comments on commit 19be4c6

Please sign in to comment.