Skip to content

Commit b920291

Browse files
Merge pull request microsoft#3473 from randombk/bug-genericConstraintCrash
Fix crash with unmet generic constraints
2 parents 05b8609 + 5fc4a8e commit b920291

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7275,8 +7275,8 @@ namespace ts {
72757275
checkApplicableSignature(node, args, candidateForArgumentError, assignableRelation, /*excludeArgument*/ undefined, /*reportErrors*/ true);
72767276
}
72777277
else if (candidateForTypeArgumentError) {
7278-
if (!isTaggedTemplate && (<CallExpression>node).typeArguments) {
7279-
checkTypeArguments(candidateForTypeArgumentError, (<CallExpression>node).typeArguments, [], /*reportErrors*/ true)
7278+
if (!isTaggedTemplate && typeArguments) {
7279+
checkTypeArguments(candidateForTypeArgumentError, typeArguments, [], /*reportErrors*/ true)
72807280
}
72817281
else {
72827282
Debug.assert(resultOfFailedInference.failedTypeParameterIndex >= 0);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
tests/cases/compiler/genericTypeConstraints.ts(9,27): error TS2344: Type 'FooExtended' does not satisfy the constraint 'Foo'.
2+
Property 'fooMethod' is missing in type 'FooExtended'.
3+
tests/cases/compiler/genericTypeConstraints.ts(9,31): error TS2344: Type 'FooExtended' does not satisfy the constraint 'Foo'.
4+
5+
6+
==== tests/cases/compiler/genericTypeConstraints.ts (2 errors) ====
7+
class Foo {
8+
fooMethod() {}
9+
}
10+
11+
class FooExtended { }
12+
13+
class Bar<T extends Foo> { }
14+
15+
class BarExtended extends Bar<FooExtended> {
16+
~~~~~~~~~~~~~~~~
17+
!!! error TS2344: Type 'FooExtended' does not satisfy the constraint 'Foo'.
18+
!!! error TS2344: Property 'fooMethod' is missing in type 'FooExtended'.
19+
~~~~~~~~~~~
20+
!!! error TS2344: Type 'FooExtended' does not satisfy the constraint 'Foo'.
21+
constructor() {
22+
super();
23+
}
24+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//// [genericTypeConstraints.ts]
2+
class Foo {
3+
fooMethod() {}
4+
}
5+
6+
class FooExtended { }
7+
8+
class Bar<T extends Foo> { }
9+
10+
class BarExtended extends Bar<FooExtended> {
11+
constructor() {
12+
super();
13+
}
14+
}
15+
16+
//// [genericTypeConstraints.js]
17+
var __extends = (this && this.__extends) || function (d, b) {
18+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
19+
function __() { this.constructor = d; }
20+
__.prototype = b.prototype;
21+
d.prototype = new __();
22+
};
23+
var Foo = (function () {
24+
function Foo() {
25+
}
26+
Foo.prototype.fooMethod = function () { };
27+
return Foo;
28+
})();
29+
var FooExtended = (function () {
30+
function FooExtended() {
31+
}
32+
return FooExtended;
33+
})();
34+
var Bar = (function () {
35+
function Bar() {
36+
}
37+
return Bar;
38+
})();
39+
var BarExtended = (function (_super) {
40+
__extends(BarExtended, _super);
41+
function BarExtended() {
42+
_super.call(this);
43+
}
44+
return BarExtended;
45+
})(Bar);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Foo {
2+
fooMethod() {}
3+
}
4+
5+
class FooExtended { }
6+
7+
class Bar<T extends Foo> { }
8+
9+
class BarExtended extends Bar<FooExtended> {
10+
constructor() {
11+
super();
12+
}
13+
}

0 commit comments

Comments
 (0)