コンテンツにスキップ

noRedeclare

このコンテンツはまだ日本語訳がありません。

Diagnostic Category: lint/suspicious/noRedeclare

Since: v1.0.0

Sources:

Disallow variable, function, class, and type redeclarations in the same scope.

var a = 3;
var a = 10;
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 │

let a = 3;
let a = 10;
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 │

function f() {}
function f() {}
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 │

class C {
static {
var c = 3;
var c = 10;
}
}
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 │ }

type Person = { name: string; }
class Person { name: string; }
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 │

var a = 3;
a = 10;
class Foo {
bar(a: A);
bar(a: A, b: B);
bar(a: A, b: B) {}
}