Skip to content

Commit 49be653

Browse files
committed
Added test case for invalid generic type constraints
Signed-off-by: David Li <[email protected]>
1 parent d49fe6a commit 49be653

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
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)