Skip to content

Commit ce629f0

Browse files
committed
Test duplicate identifier reporting in classes
1 parent 78bc368 commit ce629f0

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
tests/cases/compiler/classWithDuplicateIdentifier.ts(3,5): error TS2300: Duplicate identifier 'a'.
2+
tests/cases/compiler/classWithDuplicateIdentifier.ts(6,5): error TS2300: Duplicate identifier 'b'.
3+
tests/cases/compiler/classWithDuplicateIdentifier.ts(7,5): error TS2300: Duplicate identifier 'b'.
4+
tests/cases/compiler/classWithDuplicateIdentifier.ts(11,5): error TS2300: Duplicate identifier 'c'.
5+
tests/cases/compiler/classWithDuplicateIdentifier.ts(11,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type 'string'.
6+
7+
8+
==== tests/cases/compiler/classWithDuplicateIdentifier.ts (5 errors) ====
9+
class C {
10+
a(): number { return 0; } // error: duplicate identifier
11+
a: number;
12+
~
13+
!!! error TS2300: Duplicate identifier 'a'.
14+
}
15+
class K {
16+
b: number; // error: duplicate identifier
17+
~
18+
!!! error TS2300: Duplicate identifier 'b'.
19+
b(): number { return 0; }
20+
~
21+
!!! error TS2300: Duplicate identifier 'b'.
22+
}
23+
class D {
24+
c: number;
25+
c: string;
26+
~
27+
!!! error TS2300: Duplicate identifier 'c'.
28+
~
29+
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type 'string'.
30+
}
31+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// [classWithDuplicateIdentifier.ts]
2+
class C {
3+
a(): number { return 0; } // error: duplicate identifier
4+
a: number;
5+
}
6+
class K {
7+
b: number; // error: duplicate identifier
8+
b(): number { return 0; }
9+
}
10+
class D {
11+
c: number;
12+
c: string;
13+
}
14+
15+
16+
//// [classWithDuplicateIdentifier.js]
17+
var C = (function () {
18+
function C() {
19+
}
20+
C.prototype.a = function () { return 0; }; // error: duplicate identifier
21+
return C;
22+
}());
23+
var K = (function () {
24+
function K() {
25+
}
26+
K.prototype.b = function () { return 0; };
27+
return K;
28+
}());
29+
var D = (function () {
30+
function D() {
31+
}
32+
return D;
33+
}());
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class C {
2+
a(): number { return 0; } // error: duplicate identifier
3+
a: number;
4+
}
5+
class K {
6+
b: number; // error: duplicate identifier
7+
b(): number { return 0; }
8+
}
9+
class D {
10+
c: number;
11+
c: string;
12+
}

0 commit comments

Comments
 (0)