diff --git a/packages/eslint-plugin/src/rules/typedef.ts b/packages/eslint-plugin/src/rules/typedef.ts index 89ef30f54e5..4bd69d9a479 100644 --- a/packages/eslint-plugin/src/rules/typedef.ts +++ b/packages/eslint-plugin/src/rules/typedef.ts @@ -178,7 +178,11 @@ export default util.createRule<[Options], MessageIds>({ return; } - if (!node.typeAnnotation && !isForOfStatementContext(node)) { + if ( + !node.typeAnnotation && + !isForOfStatementContext(node) && + node.parent?.type !== AST_NODE_TYPES.AssignmentExpression + ) { report(node); } }, diff --git a/packages/eslint-plugin/tests/rules/typedef.test.ts b/packages/eslint-plugin/tests/rules/typedef.test.ts index d1bae842614..19b6ff5a543 100644 --- a/packages/eslint-plugin/tests/rules/typedef.test.ts +++ b/packages/eslint-plugin/tests/rules/typedef.test.ts @@ -47,7 +47,31 @@ ruleTester.run('typedef', rule, { ], }, { - code: 'const [a] = 1;', + code: '[a] = [1];', + options: [ + { + arrayDestructuring: true, + }, + ], + }, + { + code: 'b = [a] = [1];', + options: [ + { + arrayDestructuring: true, + }, + ], + }, + { + code: 'const [b]: [number] = ([a] = [1]);', + options: [ + { + arrayDestructuring: true, + }, + ], + }, + { + code: 'const [a] = [1];', options: [ { arrayDestructuring: false,