diff --git a/src/rules/prefer-immediate-return.ts b/src/rules/prefer-immediate-return.ts index 5fb1a82b..97302c5c 100644 --- a/src/rules/prefer-immediate-return.ts +++ b/src/rules/prefer-immediate-return.ts @@ -113,7 +113,7 @@ const rule: Rule.RuleModule = { function getOnlyDeclaredVariable(node: TSESTree.Statement) { if (isVariableDeclaration(node) && node.declarations.length === 1) { const { id, init } = node.declarations[0]; - if (isIdentifier(id) && init) { + if (isIdentifier(id) && init && !id.typeAnnotation) { return { id, init }; } } diff --git a/tests/rules/prefer-immediate-return.test.ts b/tests/rules/prefer-immediate-return.test.ts index d207047c..a15420e0 100644 --- a/tests/rules/prefer-immediate-return.test.ts +++ b/tests/rules/prefer-immediate-return.test.ts @@ -143,6 +143,14 @@ ruleTester.run('prefer-immediate-return', rule, { let arrow_function_no_block = (a, b) => a + b; `, }, + { + code: ` + function variable_has_type_annotation() { + let foo: number = 1; + return foo; + } + `, + }, { code: ` function variable_is_used() {