Skip to content

Commit a8aa48e

Browse files
committed
Merge pull request #5230 from Microsoft/ambient-class-merges-overloads-with-interface
Ambient class merges overloads with interface
2 parents 5b94698 + 92c2d48 commit a8aa48e

5 files changed

+71
-1
lines changed

src/compiler/checker.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11046,7 +11046,13 @@ namespace ts {
1104611046

1104711047
function getEffectiveDeclarationFlags(n: Node, flagsToCheck: NodeFlags): NodeFlags {
1104811048
let flags = getCombinedNodeFlags(n);
11049-
if (n.parent.kind !== SyntaxKind.InterfaceDeclaration && isInAmbientContext(n)) {
11049+
11050+
// children of classes (even ambient classes) should not be marked as ambient or export
11051+
// because those flags have no useful semantics there.
11052+
if (n.parent.kind !== SyntaxKind.InterfaceDeclaration &&
11053+
n.parent.kind !== SyntaxKind.ClassDeclaration &&
11054+
n.parent.kind !== SyntaxKind.ClassExpression &&
11055+
isInAmbientContext(n)) {
1105011056
if (!(flags & NodeFlags.Ambient)) {
1105111057
// It is nested in an ambient context, which means it is automatically exported
1105211058
flags |= NodeFlags.Export;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//// [ambientClassMergesOverloadsWithInterface.ts]
2+
declare class C {
3+
baz(): any;
4+
foo(n: number): any;
5+
}
6+
interface C {
7+
foo(n: number): any;
8+
bar(): any;
9+
}
10+
11+
12+
//// [ambientClassMergesOverloadsWithInterface.js]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/ambientClassMergesOverloadsWithInterface.ts ===
2+
declare class C {
3+
>C : Symbol(C, Decl(ambientClassMergesOverloadsWithInterface.ts, 0, 0), Decl(ambientClassMergesOverloadsWithInterface.ts, 3, 1))
4+
5+
baz(): any;
6+
>baz : Symbol(baz, Decl(ambientClassMergesOverloadsWithInterface.ts, 0, 17))
7+
8+
foo(n: number): any;
9+
>foo : Symbol(foo, Decl(ambientClassMergesOverloadsWithInterface.ts, 1, 15), Decl(ambientClassMergesOverloadsWithInterface.ts, 4, 13))
10+
>n : Symbol(n, Decl(ambientClassMergesOverloadsWithInterface.ts, 2, 8))
11+
}
12+
interface C {
13+
>C : Symbol(C, Decl(ambientClassMergesOverloadsWithInterface.ts, 0, 0), Decl(ambientClassMergesOverloadsWithInterface.ts, 3, 1))
14+
15+
foo(n: number): any;
16+
>foo : Symbol(foo, Decl(ambientClassMergesOverloadsWithInterface.ts, 1, 15), Decl(ambientClassMergesOverloadsWithInterface.ts, 4, 13))
17+
>n : Symbol(n, Decl(ambientClassMergesOverloadsWithInterface.ts, 5, 8))
18+
19+
bar(): any;
20+
>bar : Symbol(bar, Decl(ambientClassMergesOverloadsWithInterface.ts, 5, 24))
21+
}
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/compiler/ambientClassMergesOverloadsWithInterface.ts ===
2+
declare class C {
3+
>C : C
4+
5+
baz(): any;
6+
>baz : () => any
7+
8+
foo(n: number): any;
9+
>foo : { (n: number): any; (n: number): any; }
10+
>n : number
11+
}
12+
interface C {
13+
>C : C
14+
15+
foo(n: number): any;
16+
>foo : { (n: number): any; (n: number): any; }
17+
>n : number
18+
19+
bar(): any;
20+
>bar : () => any
21+
}
22+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
declare class C {
2+
baz(): any;
3+
foo(n: number): any;
4+
}
5+
interface C {
6+
foo(n: number): any;
7+
bar(): any;
8+
}

0 commit comments

Comments
 (0)