Skip to content

Commit 65ca771

Browse files
committed
Add test
1 parent b379e7f commit 65ca771

5 files changed

+133
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
tests/cases/compiler/relatedViaDiscriminatedTypeNoError.ts(10,19): error TS2322: Type 'Model' is not assignable to type '{ flag: false; }'.
2+
Types of property 'flag' are incompatible.
3+
Type 'boolean' is not assignable to type 'false'.
4+
5+
6+
==== tests/cases/compiler/relatedViaDiscriminatedTypeNoError.ts (1 errors) ====
7+
class Model {
8+
constructor(public flag: boolean) {}
9+
}
10+
11+
type DiscriminatedUnion = { flag: true } | { flag: false };
12+
class A<T extends DiscriminatedUnion> {
13+
constructor(public model: T) { }
14+
}
15+
16+
class B extends A<Model> { }
17+
~~~~~
18+
!!! error TS2322: Type 'Model' is not assignable to type '{ flag: false; }'.
19+
!!! error TS2322: Types of property 'flag' are incompatible.
20+
!!! error TS2322: Type 'boolean' is not assignable to type 'false'.
21+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//// [relatedViaDiscriminatedTypeNoError.ts]
2+
class Model {
3+
constructor(public flag: boolean) {}
4+
}
5+
6+
type DiscriminatedUnion = { flag: true } | { flag: false };
7+
class A<T extends DiscriminatedUnion> {
8+
constructor(public model: T) { }
9+
}
10+
11+
class B extends A<Model> { }
12+
13+
14+
//// [relatedViaDiscriminatedTypeNoError.js]
15+
var __extends = (this && this.__extends) || (function () {
16+
var extendStatics = function (d, b) {
17+
extendStatics = Object.setPrototypeOf ||
18+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
19+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
20+
return extendStatics(d, b);
21+
};
22+
return function (d, b) {
23+
if (typeof b !== "function" && b !== null)
24+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
25+
extendStatics(d, b);
26+
function __() { this.constructor = d; }
27+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
28+
};
29+
})();
30+
var Model = /** @class */ (function () {
31+
function Model(flag) {
32+
this.flag = flag;
33+
}
34+
return Model;
35+
}());
36+
var A = /** @class */ (function () {
37+
function A(model) {
38+
this.model = model;
39+
}
40+
return A;
41+
}());
42+
var B = /** @class */ (function (_super) {
43+
__extends(B, _super);
44+
function B() {
45+
return _super !== null && _super.apply(this, arguments) || this;
46+
}
47+
return B;
48+
}(A));
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== tests/cases/compiler/relatedViaDiscriminatedTypeNoError.ts ===
2+
class Model {
3+
>Model : Symbol(Model, Decl(relatedViaDiscriminatedTypeNoError.ts, 0, 0))
4+
5+
constructor(public flag: boolean) {}
6+
>flag : Symbol(Model.flag, Decl(relatedViaDiscriminatedTypeNoError.ts, 1, 16))
7+
}
8+
9+
type DiscriminatedUnion = { flag: true } | { flag: false };
10+
>DiscriminatedUnion : Symbol(DiscriminatedUnion, Decl(relatedViaDiscriminatedTypeNoError.ts, 2, 1))
11+
>flag : Symbol(flag, Decl(relatedViaDiscriminatedTypeNoError.ts, 4, 27))
12+
>flag : Symbol(flag, Decl(relatedViaDiscriminatedTypeNoError.ts, 4, 44))
13+
14+
class A<T extends DiscriminatedUnion> {
15+
>A : Symbol(A, Decl(relatedViaDiscriminatedTypeNoError.ts, 4, 59))
16+
>T : Symbol(T, Decl(relatedViaDiscriminatedTypeNoError.ts, 5, 8))
17+
>DiscriminatedUnion : Symbol(DiscriminatedUnion, Decl(relatedViaDiscriminatedTypeNoError.ts, 2, 1))
18+
19+
constructor(public model: T) { }
20+
>model : Symbol(A.model, Decl(relatedViaDiscriminatedTypeNoError.ts, 6, 16))
21+
>T : Symbol(T, Decl(relatedViaDiscriminatedTypeNoError.ts, 5, 8))
22+
}
23+
24+
class B extends A<Model> { }
25+
>B : Symbol(B, Decl(relatedViaDiscriminatedTypeNoError.ts, 7, 1))
26+
>A : Symbol(A, Decl(relatedViaDiscriminatedTypeNoError.ts, 4, 59))
27+
>Model : Symbol(Model, Decl(relatedViaDiscriminatedTypeNoError.ts, 0, 0))
28+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
=== tests/cases/compiler/relatedViaDiscriminatedTypeNoError.ts ===
2+
class Model {
3+
>Model : Model
4+
5+
constructor(public flag: boolean) {}
6+
>flag : boolean
7+
}
8+
9+
type DiscriminatedUnion = { flag: true } | { flag: false };
10+
>DiscriminatedUnion : { flag: true; } | { flag: false; }
11+
>flag : true
12+
>true : true
13+
>flag : false
14+
>false : false
15+
16+
class A<T extends DiscriminatedUnion> {
17+
>A : A<T>
18+
19+
constructor(public model: T) { }
20+
>model : T
21+
}
22+
23+
class B extends A<Model> { }
24+
>B : B
25+
>A : A<Model>
26+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Model {
2+
constructor(public flag: boolean) {}
3+
}
4+
5+
type DiscriminatedUnion = { flag: true } | { flag: false };
6+
class A<T extends DiscriminatedUnion> {
7+
constructor(public model: T) { }
8+
}
9+
10+
class B extends A<Model> { }

0 commit comments

Comments
 (0)