diff --git a/packages/eslint-plugin/src/rules/return-await.ts b/packages/eslint-plugin/src/rules/return-await.ts index c7dc42888b6..940dfe94023 100644 --- a/packages/eslint-plugin/src/rules/return-await.ts +++ b/packages/eslint-plugin/src/rules/return-await.ts @@ -153,8 +153,15 @@ export default util.createRule({ function insertAwait( fixer: TSESLint.RuleFixer, node: TSESTree.Expression, - ): TSESLint.RuleFix | null { - return fixer.insertTextBefore(node, 'await '); + ): TSESLint.RuleFix | TSESLint.RuleFix[] { + if (node.type !== AST_NODE_TYPES.TSAsExpression) { + return fixer.insertTextBefore(node, 'await '); + } + + return [ + fixer.insertTextBefore(node, 'await ('), + fixer.insertTextAfter(node, ')'), + ]; } function test(node: TSESTree.Expression, expression: ts.Node): void { diff --git a/packages/eslint-plugin/tests/rules/return-await.test.ts b/packages/eslint-plugin/tests/rules/return-await.test.ts index 91f3a71157b..1c0a9cdd2a1 100644 --- a/packages/eslint-plugin/tests/rules/return-await.test.ts +++ b/packages/eslint-plugin/tests/rules/return-await.test.ts @@ -842,6 +842,35 @@ const buzz = async () => ((await foo()) ? 1 : await bar()); }, ], }, + { + // https://github.com/typescript-eslint/typescript-eslint/issues/2109 + code: ` +async function test(): Promise { + const res = await fetch('...'); + try { + return res.json() as Promise; + } catch (err) { + throw Error('Request Failed.'); + } +} + `, + output: ` +async function test(): Promise { + const res = await fetch('...'); + try { + return await (res.json() as Promise); + } catch (err) { + throw Error('Request Failed.'); + } +} + `, + errors: [ + { + line: 5, + messageId: 'requiredPromiseAwait', + }, + ], + }, { code: ` async function test() {