Skip to content

Module merge with constructors #5257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3679,7 +3679,9 @@ namespace ts {
function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature {
let links = getNodeLinks(declaration);
if (!links.resolvedSignature) {
let classType = declaration.kind === SyntaxKind.Constructor ? getDeclaredTypeOfClassOrInterface((<ClassDeclaration>declaration.parent).symbol) : undefined;
let classType = declaration.kind === SyntaxKind.Constructor ?
getDeclaredTypeOfClassOrInterface(getMergedSymbol((<ClassDeclaration>declaration.parent).symbol))
: undefined;
let typeParameters = classType ? classType.localTypeParameters :
declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined;
let parameters: Symbol[] = [];
Expand Down
38 changes: 38 additions & 0 deletions tests/baselines/reference/moduleMergeConstructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//// [tests/cases/compiler/moduleMergeConstructor.ts] ////

//// [foo.d.ts]

declare module "foo" {
export class Foo {
constructor();
method1(): any;
}
}

//// [foo-ext.d.ts]
declare module "foo" {
export interface Foo {
method2(): any;
}
}

//// [index.ts]
import * as foo from "foo";

class Test {
bar: foo.Foo;
constructor() {
this.bar = new foo.Foo();
}
}


//// [index.js]
define(["require", "exports", "foo"], function (require, exports, foo) {
var Test = (function () {
function Test() {
this.bar = new foo.Foo();
}
return Test;
})();
});
45 changes: 45 additions & 0 deletions tests/baselines/reference/moduleMergeConstructor.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
=== tests/cases/compiler/foo.d.ts ===

declare module "foo" {
export class Foo {
>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22))

constructor();
method1(): any;
>method1 : Symbol(method1, Decl(foo.d.ts, 3, 22))
}
}

=== tests/cases/compiler/foo-ext.d.ts ===
declare module "foo" {
export interface Foo {
>Foo : Symbol(Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22))

method2(): any;
>method2 : Symbol(method2, Decl(foo-ext.d.ts, 1, 26))
}
}

=== tests/cases/compiler/index.ts ===
import * as foo from "foo";
>foo : Symbol(foo, Decl(index.ts, 0, 6))

class Test {
>Test : Symbol(Test, Decl(index.ts, 0, 27))

bar: foo.Foo;
>bar : Symbol(bar, Decl(index.ts, 2, 12))
>foo : Symbol(foo, Decl(index.ts, 0, 6))
>Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22))

constructor() {
this.bar = new foo.Foo();
>this.bar : Symbol(bar, Decl(index.ts, 2, 12))
>this : Symbol(Test, Decl(index.ts, 0, 27))
>bar : Symbol(bar, Decl(index.ts, 2, 12))
>foo.Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22))
>foo : Symbol(foo, Decl(index.ts, 0, 6))
>Foo : Symbol(foo.Foo, Decl(foo.d.ts, 1, 22), Decl(foo-ext.d.ts, 0, 22))
}
}

47 changes: 47 additions & 0 deletions tests/baselines/reference/moduleMergeConstructor.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
=== tests/cases/compiler/foo.d.ts ===

declare module "foo" {
export class Foo {
>Foo : Foo

constructor();
method1(): any;
>method1 : () => any
}
}

=== tests/cases/compiler/foo-ext.d.ts ===
declare module "foo" {
export interface Foo {
>Foo : Foo

method2(): any;
>method2 : () => any
}
}

=== tests/cases/compiler/index.ts ===
import * as foo from "foo";
>foo : typeof foo

class Test {
>Test : Test

bar: foo.Foo;
>bar : foo.Foo
>foo : any
>Foo : foo.Foo

constructor() {
this.bar = new foo.Foo();
>this.bar = new foo.Foo() : foo.Foo
>this.bar : foo.Foo
>this : this
>bar : foo.Foo
>new foo.Foo() : foo.Foo
>foo.Foo : typeof foo.Foo
>foo : typeof foo
>Foo : typeof foo.Foo
}
}

26 changes: 26 additions & 0 deletions tests/cases/compiler/moduleMergeConstructor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @module: amd

// @filename: foo.d.ts
declare module "foo" {
export class Foo {
constructor();
method1(): any;
}
}

// @filename: foo-ext.d.ts
declare module "foo" {
export interface Foo {
method2(): any;
}
}

// @filename: index.ts
import * as foo from "foo";

class Test {
bar: foo.Foo;
constructor() {
this.bar = new foo.Foo();
}
}