Skip to content

Commit e98a76f

Browse files
committed
Merge pull request microsoft#5257 from Microsoft/module-merge-with-constructors
Module merge with constructors
2 parents bb369f1 + c66bbd8 commit e98a76f

File tree

5 files changed

+159
-1
lines changed

5 files changed

+159
-1
lines changed

src/compiler/checker.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -3714,7 +3714,9 @@ namespace ts {
37143714
function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature {
37153715
let links = getNodeLinks(declaration);
37163716
if (!links.resolvedSignature) {
3717-
let classType = declaration.kind === SyntaxKind.Constructor ? getDeclaredTypeOfClassOrInterface((<ClassDeclaration>declaration.parent).symbol) : undefined;
3717+
let classType = declaration.kind === SyntaxKind.Constructor ?
3718+
getDeclaredTypeOfClassOrInterface(getMergedSymbol((<ClassDeclaration>declaration.parent).symbol))
3719+
: undefined;
37183720
let typeParameters = classType ? classType.localTypeParameters :
37193721
declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined;
37203722
let parameters: Symbol[] = [];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//// [tests/cases/compiler/moduleMergeConstructor.ts] ////
2+
3+
//// [foo.d.ts]
4+
5+
declare module "foo" {
6+
export class Foo {
7+
constructor();
8+
method1(): any;
9+
}
10+
}
11+
12+
//// [foo-ext.d.ts]
13+
declare module "foo" {
14+
export interface Foo {
15+
method2(): any;
16+
}
17+
}
18+
19+
//// [index.ts]
20+
import * as foo from "foo";
21+
22+
class Test {
23+
bar: foo.Foo;
24+
constructor() {
25+
this.bar = new foo.Foo();
26+
}
27+
}
28+
29+
30+
//// [index.js]
31+
define(["require", "exports", "foo"], function (require, exports, foo) {
32+
var Test = (function () {
33+
function Test() {
34+
this.bar = new foo.Foo();
35+
}
36+
return Test;
37+
})();
38+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
=== tests/cases/compiler/foo.d.ts ===
2+
3+
declare module "foo" {
4+
export class Foo {
5+
>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22))
6+
7+
constructor();
8+
method1(): any;
9+
>method1 : Symbol(method1, Decl(foo.d.ts, 3, 22))
10+
}
11+
}
12+
13+
=== tests/cases/compiler/foo-ext.d.ts ===
14+
declare module "foo" {
15+
export interface Foo {
16+
>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22))
17+
18+
method2(): any;
19+
>method2 : Symbol(method2, Decl(foo-ext.d.ts, 1, 26))
20+
}
21+
}
22+
23+
=== tests/cases/compiler/index.ts ===
24+
import * as foo from "foo";
25+
>foo : Symbol(foo, Decl(index.ts, 0, 6))
26+
27+
class Test {
28+
>Test : Symbol(Test, Decl(index.ts, 0, 27))
29+
30+
bar: foo.Foo;
31+
>bar : Symbol(bar, Decl(index.ts, 2, 12))
32+
>foo : Symbol(foo, Decl(index.ts, 0, 6))
33+
>Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22))
34+
35+
constructor() {
36+
this.bar = new foo.Foo();
37+
>this.bar : Symbol(bar, Decl(index.ts, 2, 12))
38+
>this : Symbol(Test, Decl(index.ts, 0, 27))
39+
>bar : Symbol(bar, Decl(index.ts, 2, 12))
40+
>foo.Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22))
41+
>foo : Symbol(foo, Decl(index.ts, 0, 6))
42+
>Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22))
43+
}
44+
}
45+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
=== tests/cases/compiler/foo.d.ts ===
2+
3+
declare module "foo" {
4+
export class Foo {
5+
>Foo : Foo
6+
7+
constructor();
8+
method1(): any;
9+
>method1 : () => any
10+
}
11+
}
12+
13+
=== tests/cases/compiler/foo-ext.d.ts ===
14+
declare module "foo" {
15+
export interface Foo {
16+
>Foo : Foo
17+
18+
method2(): any;
19+
>method2 : () => any
20+
}
21+
}
22+
23+
=== tests/cases/compiler/index.ts ===
24+
import * as foo from "foo";
25+
>foo : typeof foo
26+
27+
class Test {
28+
>Test : Test
29+
30+
bar: foo.Foo;
31+
>bar : foo.Foo
32+
>foo : any
33+
>Foo : foo.Foo
34+
35+
constructor() {
36+
this.bar = new foo.Foo();
37+
>this.bar = new foo.Foo() : foo.Foo
38+
>this.bar : foo.Foo
39+
>this : this
40+
>bar : foo.Foo
41+
>new foo.Foo() : foo.Foo
42+
>foo.Foo : typeof foo.Foo
43+
>foo : typeof foo
44+
>Foo : typeof foo.Foo
45+
}
46+
}
47+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// @module: amd
2+
3+
// @filename: foo.d.ts
4+
declare module "foo" {
5+
export class Foo {
6+
constructor();
7+
method1(): any;
8+
}
9+
}
10+
11+
// @filename: foo-ext.d.ts
12+
declare module "foo" {
13+
export interface Foo {
14+
method2(): any;
15+
}
16+
}
17+
18+
// @filename: index.ts
19+
import * as foo from "foo";
20+
21+
class Test {
22+
bar: foo.Foo;
23+
constructor() {
24+
this.bar = new foo.Foo();
25+
}
26+
}

0 commit comments

Comments
 (0)