Skip to content
Closed
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
1 change: 1 addition & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3663,6 +3663,7 @@ namespace ts {
const sig = typeParamCount ? getSignatureInstantiation(baseSig, typeArguments) : cloneSignature(baseSig);
sig.typeParameters = classType.localTypeParameters;
sig.resolvedReturnType = classType;
sig.target = undefined;
result.push(sig);
}
}
Expand Down
49 changes: 49 additions & 0 deletions tests/baselines/reference/inferInstanceOfSubclass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//// [inferInstanceOfSubclass.ts]
function create<T>(ctor: { new(): T }) {
return new ctor();
}
class C<U> { c: U }
class D<V> extends C<V> { d: V }
let d = create(D);

class A { a: number }
class B<T> extends A { b: T }
let b = create(B);



//// [inferInstanceOfSubclass.js]
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
function create(ctor) {
return new ctor();
}
var C = (function () {
function C() {
}
return C;
}());
var D = (function (_super) {
__extends(D, _super);
function D() {
_super.apply(this, arguments);
}
return D;
}(C));
var d = create(D);
var A = (function () {
function A() {
}
return A;
}());
var B = (function (_super) {
__extends(B, _super);
function B() {
_super.apply(this, arguments);
}
return B;
}(A));
var b = create(B);
46 changes: 46 additions & 0 deletions tests/baselines/reference/inferInstanceOfSubclass.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
=== tests/cases/compiler/inferInstanceOfSubclass.ts ===
function create<T>(ctor: { new(): T }) {
>create : Symbol(create, Decl(inferInstanceOfSubclass.ts, 0, 0))
>T : Symbol(T, Decl(inferInstanceOfSubclass.ts, 0, 16))
>ctor : Symbol(ctor, Decl(inferInstanceOfSubclass.ts, 0, 19))
>T : Symbol(T, Decl(inferInstanceOfSubclass.ts, 0, 16))

return new ctor();
>ctor : Symbol(ctor, Decl(inferInstanceOfSubclass.ts, 0, 19))
}
class C<U> { c: U }
>C : Symbol(C, Decl(inferInstanceOfSubclass.ts, 2, 1))
>U : Symbol(U, Decl(inferInstanceOfSubclass.ts, 3, 8))
>c : Symbol(c, Decl(inferInstanceOfSubclass.ts, 3, 12))
>U : Symbol(U, Decl(inferInstanceOfSubclass.ts, 3, 8))

class D<V> extends C<V> { d: V }
>D : Symbol(D, Decl(inferInstanceOfSubclass.ts, 3, 19))
>V : Symbol(V, Decl(inferInstanceOfSubclass.ts, 4, 8))
>C : Symbol(C, Decl(inferInstanceOfSubclass.ts, 2, 1))
>V : Symbol(V, Decl(inferInstanceOfSubclass.ts, 4, 8))
>d : Symbol(d, Decl(inferInstanceOfSubclass.ts, 4, 25))
>V : Symbol(V, Decl(inferInstanceOfSubclass.ts, 4, 8))

let d = create(D);
>d : Symbol(d, Decl(inferInstanceOfSubclass.ts, 5, 3))
>create : Symbol(create, Decl(inferInstanceOfSubclass.ts, 0, 0))
>D : Symbol(D, Decl(inferInstanceOfSubclass.ts, 3, 19))

class A { a: number }
>A : Symbol(A, Decl(inferInstanceOfSubclass.ts, 5, 18))
>a : Symbol(a, Decl(inferInstanceOfSubclass.ts, 7, 9))

class B<T> extends A { b: T }
>B : Symbol(B, Decl(inferInstanceOfSubclass.ts, 7, 21))
>T : Symbol(T, Decl(inferInstanceOfSubclass.ts, 8, 8))
>A : Symbol(A, Decl(inferInstanceOfSubclass.ts, 5, 18))
>b : Symbol(b, Decl(inferInstanceOfSubclass.ts, 8, 22))
>T : Symbol(T, Decl(inferInstanceOfSubclass.ts, 8, 8))

let b = create(B);
>b : Symbol(b, Decl(inferInstanceOfSubclass.ts, 9, 3))
>create : Symbol(create, Decl(inferInstanceOfSubclass.ts, 0, 0))
>B : Symbol(B, Decl(inferInstanceOfSubclass.ts, 7, 21))


49 changes: 49 additions & 0 deletions tests/baselines/reference/inferInstanceOfSubclass.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
=== tests/cases/compiler/inferInstanceOfSubclass.ts ===
function create<T>(ctor: { new(): T }) {
>create : <T>(ctor: new () => T) => T
>T : T
>ctor : new () => T
>T : T

return new ctor();
>new ctor() : T
>ctor : new () => T
}
class C<U> { c: U }
>C : C<U>
>U : U
>c : U
>U : U

class D<V> extends C<V> { d: V }
>D : D<V>
>V : V
>C : C<V>
>V : V
>d : V
>V : V

let d = create(D);
>d : D<any>
>create(D) : D<any>
>create : <T>(ctor: new () => T) => T
>D : typeof D

class A { a: number }
>A : A
>a : number

class B<T> extends A { b: T }
>B : B<T>
>T : T
>A : A
>b : T
>T : T

let b = create(B);
>b : B<any>
>create(B) : B<any>
>create : <T>(ctor: new () => T) => T
>B : typeof B


11 changes: 11 additions & 0 deletions tests/cases/compiler/inferInstanceOfSubclass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function create<T>(ctor: { new(): T }) {
return new ctor();
}
class C<U> { c: U }
class D<V> extends C<V> { d: V }
let d = create(D);

class A { a: number }
class B<T> extends A { b: T }
let b = create(B);