Skip to content

Commit bb3e9d6

Browse files
authored
docs(eslint-plugin): [no-redeclare] clearly document type/variable redeclare case (typescript-eslint#2500)
Addresses typescript-eslint#2477
1 parent f887ab5 commit bb3e9d6

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/eslint-plugin/docs/rules/no-redeclare.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,14 @@ function Baz() {}
6666
namespace Baz {}
6767
```
6868

69+
**Note:** Even with this option set to true, this rule will report if you name a type and a variable the same name. **_This is intentional_**.
70+
Declaring a variable and a type and a variable the same is usually an accident, and it can lead to hard-to-understand code.
71+
If you have a rare case where you're intentionally naming a type the same name as a variable, use a disable comment. For example:
72+
73+
```ts
74+
type something = string;
75+
// eslint-disable-next-line @typescript-eslint/no-redeclare -- intentionally naming the variable the same as the type
76+
const something = 2;
77+
```
78+
6979
<sup>Taken with ❤️ [from ESLint core](https://github.com/eslint/eslint/blob/master/docs/rules/no-redeclare.md)</sup>

packages/eslint-plugin/tests/rules/no-redeclare.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,5 +627,20 @@ namespace A {}
627627
},
628628
],
629629
},
630+
{
631+
code: `
632+
type something = string;
633+
const something = 2;
634+
`,
635+
errors: [
636+
{
637+
messageId: 'redeclared',
638+
data: {
639+
id: 'something',
640+
},
641+
line: 3,
642+
},
643+
],
644+
},
630645
],
631646
});

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