Skip to content

Commit 35a303a

Browse files
committed
Do not report errors for classes and interfaces merging
1 parent 302db0a commit 35a303a

32 files changed

+1037
-265
lines changed

src/compiler/checker.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12874,11 +12874,6 @@ namespace ts {
1287412874
}
1287512875
checkClassLikeDeclaration(node);
1287612876

12877-
// Interfaces cannot be merged with non-ambient classes.
12878-
if (getSymbolOfNode(node).flags & SymbolFlags.Interface && !isInAmbientContext(node)) {
12879-
error(node, Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface);
12880-
}
12881-
1288212877
forEach(node.members, checkSourceElement);
1288312878
}
1288412879

@@ -13164,16 +13159,6 @@ namespace ts {
1316413159
checkIndexConstraints(type);
1316513160
}
1316613161
}
13167-
13168-
// Interfaces cannot merge with non-ambient classes.
13169-
if (symbol && symbol.declarations) {
13170-
for (let declaration of symbol.declarations) {
13171-
if (declaration.kind === SyntaxKind.ClassDeclaration && !isInAmbientContext(declaration)) {
13172-
error(node, Diagnostics.Only_an_ambient_class_can_be_merged_with_an_interface);
13173-
break;
13174-
}
13175-
}
13176-
}
1317713162
}
1317813163
forEach(getInterfaceBaseTypeNodes(node), heritageElement => {
1317913164
if (!isSupportedExpressionWithTypeArguments(heritageElement)) {

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,10 +1620,6 @@
16201620
"category": "Error",
16211621
"code":2517
16221622
},
1623-
"Only an ambient class can be merged with an interface.": {
1624-
"category": "Error",
1625-
"code": 2518
1626-
},
16271623
"Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": {
16281624
"category": "Error",
16291625
"code": 2520

tests/baselines/reference/augmentedTypesClass2.errors.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
tests/cases/compiler/augmentedTypesClass2.ts(4,7): error TS2518: Only an ambient class can be merged with an interface.
2-
tests/cases/compiler/augmentedTypesClass2.ts(10,11): error TS2518: Only an ambient class can be merged with an interface.
31
tests/cases/compiler/augmentedTypesClass2.ts(16,7): error TS2300: Duplicate identifier 'c33'.
42
tests/cases/compiler/augmentedTypesClass2.ts(21,6): error TS2300: Duplicate identifier 'c33'.
53

64

7-
==== tests/cases/compiler/augmentedTypesClass2.ts (4 errors) ====
5+
==== tests/cases/compiler/augmentedTypesClass2.ts (2 errors) ====
86
// Checking class with other things in type space not value space
97

108
// class then interface
119
class c11 { // error
12-
~~~
13-
!!! error TS2518: Only an ambient class can be merged with an interface.
1410
foo() {
1511
return 1;
1612
}
1713
}
1814

1915
interface c11 { // error
20-
~~~
21-
!!! error TS2518: Only an ambient class can be merged with an interface.
2216
bar(): void;
2317
}
2418

tests/baselines/reference/augmentedTypesInterface.errors.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
tests/cases/compiler/augmentedTypesInterface.ts(12,11): error TS2518: Only an ambient class can be merged with an interface.
2-
tests/cases/compiler/augmentedTypesInterface.ts(16,7): error TS2518: Only an ambient class can be merged with an interface.
31
tests/cases/compiler/augmentedTypesInterface.ts(23,11): error TS2300: Duplicate identifier 'i3'.
42
tests/cases/compiler/augmentedTypesInterface.ts(26,6): error TS2300: Duplicate identifier 'i3'.
53

64

7-
==== tests/cases/compiler/augmentedTypesInterface.ts (4 errors) ====
5+
==== tests/cases/compiler/augmentedTypesInterface.ts (2 errors) ====
86
// interface then interface
97

108
interface i {
@@ -17,14 +15,10 @@ tests/cases/compiler/augmentedTypesInterface.ts(26,6): error TS2300: Duplicate i
1715

1816
// interface then class
1917
interface i2 { // error
20-
~~
21-
!!! error TS2518: Only an ambient class can be merged with an interface.
2218
foo(): void;
2319
}
2420

2521
class i2 { // error
26-
~~
27-
!!! error TS2518: Only an ambient class can be merged with an interface.
2822
bar() {
2923
return 1;
3024
}

tests/baselines/reference/classAbstractMergedDeclaration.errors.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(7,16): error TS2518: Only an ambient class can be merged with an interface.
2-
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(8,11): error TS2518: Only an ambient class can be merged with an interface.
3-
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(10,11): error TS2518: Only an ambient class can be merged with an interface.
4-
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(11,16): error TS2518: Only an ambient class can be merged with an interface.
51
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(13,16): error TS2300: Duplicate identifier 'CC1'.
62
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(14,7): error TS2300: Duplicate identifier 'CC1'.
73
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(16,7): error TS2300: Duplicate identifier 'CC2'.
@@ -20,26 +16,18 @@ tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbst
2016
tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts(39,1): error TS2511: Cannot create an instance of the abstract class 'DCC1'.
2117

2218

23-
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts (20 errors) ====
19+
==== tests/cases/conformance/classes/classDeclarations/classAbstractKeyword/classAbstractMergedDeclaration.ts (16 errors) ====
2420
abstract class CM {}
2521
module CM {}
2622

2723
module MC {}
2824
abstract class MC {}
2925

3026
abstract class CI {}
31-
~~
32-
!!! error TS2518: Only an ambient class can be merged with an interface.
3327
interface CI {}
34-
~~
35-
!!! error TS2518: Only an ambient class can be merged with an interface.
3628

3729
interface IC {}
38-
~~
39-
!!! error TS2518: Only an ambient class can be merged with an interface.
4030
abstract class IC {}
41-
~~
42-
!!! error TS2518: Only an ambient class can be merged with an interface.
4331

4432
abstract class CC1 {}
4533
~~~

tests/baselines/reference/classAndInterfaceWithSameName.errors.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,25 @@
1-
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(1,7): error TS2518: Only an ambient class can be merged with an interface.
21
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(1,11): error TS2300: Duplicate identifier 'foo'.
3-
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(2,11): error TS2518: Only an ambient class can be merged with an interface.
42
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(2,15): error TS2300: Duplicate identifier 'foo'.
5-
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(5,11): error TS2518: Only an ambient class can be merged with an interface.
63
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(6,9): error TS2300: Duplicate identifier 'bar'.
7-
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(9,15): error TS2518: Only an ambient class can be merged with an interface.
84
tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts(10,9): error TS2300: Duplicate identifier 'bar'.
95

106

11-
==== tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts (8 errors) ====
7+
==== tests/cases/conformance/classes/classDeclarations/classAndInterfaceWithSameName.ts (4 errors) ====
128
class C { foo: string; }
13-
~
14-
!!! error TS2518: Only an ambient class can be merged with an interface.
159
~~~
1610
!!! error TS2300: Duplicate identifier 'foo'.
1711
interface C { foo: string; } // error
18-
~
19-
!!! error TS2518: Only an ambient class can be merged with an interface.
2012
~~~
2113
!!! error TS2300: Duplicate identifier 'foo'.
2214

2315
module M {
2416
class D {
25-
~
26-
!!! error TS2518: Only an ambient class can be merged with an interface.
2717
bar: string;
2818
~~~
2919
!!! error TS2300: Duplicate identifier 'bar'.
3020
}
3121

3222
interface D { // error
33-
~
34-
!!! error TS2518: Only an ambient class can be merged with an interface.
3523
bar: string;
3624
~~~
3725
!!! error TS2300: Duplicate identifier 'bar'.

tests/baselines/reference/clinterfaces.errors.txt

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=== tests/cases/compiler/clinterfaces.ts ===
2+
module M {
3+
>M : Symbol(M, Decl(clinterfaces.ts, 0, 0))
4+
5+
class C { }
6+
>C : Symbol(C, Decl(clinterfaces.ts, 0, 10), Decl(clinterfaces.ts, 1, 15))
7+
8+
interface C { }
9+
>C : Symbol(C, Decl(clinterfaces.ts, 0, 10), Decl(clinterfaces.ts, 1, 15))
10+
11+
interface D { }
12+
>D : Symbol(D, Decl(clinterfaces.ts, 2, 19), Decl(clinterfaces.ts, 3, 19))
13+
14+
class D { }
15+
>D : Symbol(D, Decl(clinterfaces.ts, 2, 19), Decl(clinterfaces.ts, 3, 19))
16+
}
17+
18+
interface Foo<T> {
19+
>Foo : Symbol(Foo, Decl(clinterfaces.ts, 5, 1), Decl(clinterfaces.ts, 9, 1))
20+
>T : Symbol(T, Decl(clinterfaces.ts, 7, 14), Decl(clinterfaces.ts, 11, 10))
21+
22+
a: string;
23+
>a : Symbol(a, Decl(clinterfaces.ts, 7, 18))
24+
}
25+
26+
class Foo<T>{
27+
>Foo : Symbol(Foo, Decl(clinterfaces.ts, 5, 1), Decl(clinterfaces.ts, 9, 1))
28+
>T : Symbol(T, Decl(clinterfaces.ts, 7, 14), Decl(clinterfaces.ts, 11, 10))
29+
30+
b: number;
31+
>b : Symbol(b, Decl(clinterfaces.ts, 11, 13))
32+
}
33+
34+
class Bar<T>{
35+
>Bar : Symbol(Bar, Decl(clinterfaces.ts, 13, 1), Decl(clinterfaces.ts, 17, 1))
36+
>T : Symbol(T, Decl(clinterfaces.ts, 15, 10), Decl(clinterfaces.ts, 19, 14))
37+
38+
b: number;
39+
>b : Symbol(b, Decl(clinterfaces.ts, 15, 13))
40+
}
41+
42+
interface Bar<T> {
43+
>Bar : Symbol(Bar, Decl(clinterfaces.ts, 13, 1), Decl(clinterfaces.ts, 17, 1))
44+
>T : Symbol(T, Decl(clinterfaces.ts, 15, 10), Decl(clinterfaces.ts, 19, 14))
45+
46+
a: string;
47+
>a : Symbol(a, Decl(clinterfaces.ts, 19, 18))
48+
}
49+
50+
export = Foo;
51+
>Foo : Symbol(Foo, Decl(clinterfaces.ts, 5, 1), Decl(clinterfaces.ts, 9, 1))
52+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=== tests/cases/compiler/clinterfaces.ts ===
2+
module M {
3+
>M : typeof M
4+
5+
class C { }
6+
>C : C
7+
8+
interface C { }
9+
>C : C
10+
11+
interface D { }
12+
>D : D
13+
14+
class D { }
15+
>D : D
16+
}
17+
18+
interface Foo<T> {
19+
>Foo : Foo<T>
20+
>T : T
21+
22+
a: string;
23+
>a : string
24+
}
25+
26+
class Foo<T>{
27+
>Foo : Foo<T>
28+
>T : T
29+
30+
b: number;
31+
>b : number
32+
}
33+
34+
class Bar<T>{
35+
>Bar : Bar<T>
36+
>T : T
37+
38+
b: number;
39+
>b : number
40+
}
41+
42+
interface Bar<T> {
43+
>Bar : Bar<T>
44+
>T : T
45+
46+
a: string;
47+
>a : string
48+
}
49+
50+
export = Foo;
51+
>Foo : Foo<T>
52+

tests/baselines/reference/declInput.errors.txt

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== tests/cases/compiler/declInput.ts ===
2+
interface bar {
3+
>bar : Symbol(bar, Decl(declInput.ts, 0, 0), Decl(declInput.ts, 2, 1))
4+
5+
}
6+
7+
class bar {
8+
>bar : Symbol(bar, Decl(declInput.ts, 0, 0), Decl(declInput.ts, 2, 1))
9+
10+
public f() { return ''; }
11+
>f : Symbol(f, Decl(declInput.ts, 4, 11))
12+
13+
public g() { return {a: <bar>null, b: undefined, c: void 4 }; }
14+
>g : Symbol(g, Decl(declInput.ts, 5, 27))
15+
>a : Symbol(a, Decl(declInput.ts, 6, 23))
16+
>bar : Symbol(bar, Decl(declInput.ts, 0, 0), Decl(declInput.ts, 2, 1))
17+
>b : Symbol(b, Decl(declInput.ts, 6, 36))
18+
>undefined : Symbol(undefined)
19+
>c : Symbol(c, Decl(declInput.ts, 6, 50))
20+
21+
public h(x = 4, y = null, z = '') { x++; }
22+
>h : Symbol(h, Decl(declInput.ts, 6, 65))
23+
>x : Symbol(x, Decl(declInput.ts, 7, 11))
24+
>y : Symbol(y, Decl(declInput.ts, 7, 17))
25+
>z : Symbol(z, Decl(declInput.ts, 7, 27))
26+
>x : Symbol(x, Decl(declInput.ts, 7, 11))
27+
}
28+

0 commit comments

Comments
 (0)