Skip to content

Commit 61154b6

Browse files
committed
Merge pull request #8713 from Microsoft/generic-inherited-default-constructor
Generic inherited default constructor
2 parents f95f51f + 60b8d0a commit 61154b6

File tree

5 files changed

+111
-6
lines changed

5 files changed

+111
-6
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4579,12 +4579,7 @@ namespace ts {
45794579
function getErasedSignature(signature: Signature): Signature {
45804580
if (!signature.typeParameters) return signature;
45814581
if (!signature.erasedSignatureCache) {
4582-
if (signature.target) {
4583-
signature.erasedSignatureCache = instantiateSignature(getErasedSignature(signature.target), signature.mapper);
4584-
}
4585-
else {
4586-
signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), /*eraseTypeParameters*/ true);
4587-
}
4582+
signature.erasedSignatureCache = instantiateSignature(signature, createTypeEraser(signature.typeParameters), /*eraseTypeParameters*/ true);
45884583
}
45894584
return signature.erasedSignatureCache;
45904585
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [genericInheritedDefaultConstructors.ts]
2+
// repro from #8166
3+
interface Constructor<T> {
4+
new(...args: any[]): T;
5+
prototype: T;
6+
}
7+
8+
class A<U> { a: U; }
9+
class B<V> extends A<V> { b: V; }
10+
var c:Constructor<B<boolean>> = B; // shouldn't error here
11+
12+
13+
//// [genericInheritedDefaultConstructors.js]
14+
var __extends = (this && this.__extends) || function (d, b) {
15+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
16+
function __() { this.constructor = d; }
17+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
18+
};
19+
var A = (function () {
20+
function A() {
21+
}
22+
return A;
23+
}());
24+
var B = (function (_super) {
25+
__extends(B, _super);
26+
function B() {
27+
_super.apply(this, arguments);
28+
}
29+
return B;
30+
}(A));
31+
var c = B; // shouldn't error here
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== tests/cases/compiler/genericInheritedDefaultConstructors.ts ===
2+
// repro from #8166
3+
interface Constructor<T> {
4+
>Constructor : Symbol(Constructor, Decl(genericInheritedDefaultConstructors.ts, 0, 0))
5+
>T : Symbol(T, Decl(genericInheritedDefaultConstructors.ts, 1, 22))
6+
7+
new(...args: any[]): T;
8+
>args : Symbol(args, Decl(genericInheritedDefaultConstructors.ts, 2, 8))
9+
>T : Symbol(T, Decl(genericInheritedDefaultConstructors.ts, 1, 22))
10+
11+
prototype: T;
12+
>prototype : Symbol(Constructor.prototype, Decl(genericInheritedDefaultConstructors.ts, 2, 27))
13+
>T : Symbol(T, Decl(genericInheritedDefaultConstructors.ts, 1, 22))
14+
}
15+
16+
class A<U> { a: U; }
17+
>A : Symbol(A, Decl(genericInheritedDefaultConstructors.ts, 4, 1))
18+
>U : Symbol(U, Decl(genericInheritedDefaultConstructors.ts, 6, 8))
19+
>a : Symbol(A.a, Decl(genericInheritedDefaultConstructors.ts, 6, 12))
20+
>U : Symbol(U, Decl(genericInheritedDefaultConstructors.ts, 6, 8))
21+
22+
class B<V> extends A<V> { b: V; }
23+
>B : Symbol(B, Decl(genericInheritedDefaultConstructors.ts, 6, 20))
24+
>V : Symbol(V, Decl(genericInheritedDefaultConstructors.ts, 7, 8))
25+
>A : Symbol(A, Decl(genericInheritedDefaultConstructors.ts, 4, 1))
26+
>V : Symbol(V, Decl(genericInheritedDefaultConstructors.ts, 7, 8))
27+
>b : Symbol(B.b, Decl(genericInheritedDefaultConstructors.ts, 7, 25))
28+
>V : Symbol(V, Decl(genericInheritedDefaultConstructors.ts, 7, 8))
29+
30+
var c:Constructor<B<boolean>> = B; // shouldn't error here
31+
>c : Symbol(c, Decl(genericInheritedDefaultConstructors.ts, 8, 3))
32+
>Constructor : Symbol(Constructor, Decl(genericInheritedDefaultConstructors.ts, 0, 0))
33+
>B : Symbol(B, Decl(genericInheritedDefaultConstructors.ts, 6, 20))
34+
>B : Symbol(B, Decl(genericInheritedDefaultConstructors.ts, 6, 20))
35+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== tests/cases/compiler/genericInheritedDefaultConstructors.ts ===
2+
// repro from #8166
3+
interface Constructor<T> {
4+
>Constructor : Constructor<T>
5+
>T : T
6+
7+
new(...args: any[]): T;
8+
>args : any[]
9+
>T : T
10+
11+
prototype: T;
12+
>prototype : T
13+
>T : T
14+
}
15+
16+
class A<U> { a: U; }
17+
>A : A<U>
18+
>U : U
19+
>a : U
20+
>U : U
21+
22+
class B<V> extends A<V> { b: V; }
23+
>B : B<V>
24+
>V : V
25+
>A : A<V>
26+
>V : V
27+
>b : V
28+
>V : V
29+
30+
var c:Constructor<B<boolean>> = B; // shouldn't error here
31+
>c : Constructor<B<boolean>>
32+
>Constructor : Constructor<T>
33+
>B : B<V>
34+
>B : typeof B
35+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// repro from #8166
2+
interface Constructor<T> {
3+
new(...args: any[]): T;
4+
prototype: T;
5+
}
6+
7+
class A<U> { a: U; }
8+
class B<V> extends A<V> { b: V; }
9+
var c:Constructor<B<boolean>> = B; // shouldn't error here

0 commit comments

Comments
 (0)