Skip to content

Commit 2ada5af

Browse files
authored
fix(eslint-plugin): [typedef] false positive for rest parameter with array destructuring (typescript-eslint#2441)
1 parent cdb9807 commit 2ada5af

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/eslint-plugin/src/rules/typedef.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ export default util.createRule<[Options], MessageIds>({
141141

142142
return {
143143
ArrayPattern(node): void {
144+
if (
145+
node.parent?.type === AST_NODE_TYPES.RestElement &&
146+
node.parent.typeAnnotation
147+
) {
148+
return;
149+
}
144150
if (
145151
options[OptionKeys.ArrayDestructuring] &&
146152
!node.typeAnnotation &&

packages/eslint-plugin/tests/rules/typedef.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ const ruleTester = new RuleTester({
1414
ruleTester.run('typedef', rule, {
1515
valid: [
1616
// Array destructuring
17+
{
18+
code: 'function foo(...[a]: string[]) {}',
19+
options: [
20+
{
21+
arrayDestructuring: true,
22+
},
23+
],
24+
},
25+
{
26+
code: 'const foo = (...[a]: string[]) => {};',
27+
options: [
28+
{
29+
arrayDestructuring: true,
30+
},
31+
],
32+
},
1733
{
1834
code: 'const [a]: [number] = [1];',
1935
options: [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy