noRedeclare
诊断类别:lint/suspicious/noRedeclare
¥Diagnostic Category: lint/suspicious/noRedeclare
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
no-redeclare
¥Same as:
no-redeclare
-
与以下相同:
@typescript-eslint/no-redeclare
¥Same as:
@typescript-eslint/no-redeclare
禁止在同一范围内重新声明变量、函数、类和类型。
¥Disallow variable, function, class, and type redeclarations in the same scope.
¥Examples
¥Invalid
code-block.js:2:5 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Shouldn’t redeclare ‘a’. Consider to delete it or rename it.
1 │ var a = 3;
> 2 │ var a = 10;
│ ^
3 │
ℹ ‘a’ is defined here:
> 1 │ var a = 3;
│ ^
2 │ var a = 10;
3 │
code-block.js:2:5 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Shouldn’t redeclare ‘a’. Consider to delete it or rename it.
1 │ let a = 3;
> 2 │ let a = 10;
│ ^
3 │
ℹ ‘a’ is defined here:
> 1 │ let a = 3;
│ ^
2 │ let a = 10;
3 │
code-block.js:2:10 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Shouldn’t redeclare ‘f’. Consider to delete it or rename it.
1 │ function f() {}
> 2 │ function f() {}
│ ^
3 │
ℹ ‘f’ is defined here:
> 1 │ function f() {}
│ ^
2 │ function f() {}
3 │
code-block.js:4:13 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Shouldn’t redeclare ‘c’. Consider to delete it or rename it.
2 │ static {
3 │ var c = 3;
> 4 │ var c = 10;
│ ^
5 │ }
6 │ }
ℹ ‘c’ is defined here:
1 │ class C {
2 │ static {
> 3 │ var c = 3;
│ ^
4 │ var c = 10;
5 │ }
code-block.ts:2:7 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Shouldn’t redeclare ‘Person’. Consider to delete it or rename it.
1 │ type Person = { name: string; }
> 2 │ class Person { name: string; }
│ ^^^^^^
3 │
ℹ ‘Person’ is defined here:
> 1 │ type Person = { name: string; }
│ ^^^^^^
2 │ class Person { name: string; }
3 │
¥Valid
¥Related links