Skip to content

Commit 2efa697

Browse files
Accepted baselines.
1 parent 5cbf17d commit 2efa697

5 files changed

+443
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts(18,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
2+
tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts(19,10): error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
3+
4+
5+
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags02.ts (2 errors) ====
6+
7+
type Kind = "A" | "B"
8+
9+
interface Entity {
10+
kind: Kind;
11+
}
12+
13+
interface A extends Entity {
14+
kind: "A";
15+
a: number;
16+
}
17+
18+
interface B extends Entity {
19+
kind: "B";
20+
b: string;
21+
}
22+
23+
function hasKind(entity: Entity, kind: "A"): entity is A;
24+
~~~~~~~
25+
!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
26+
function hasKind(entity: Entity, kind: "B"): entity is B;
27+
~~~~~~~
28+
!!! error TS2382: Specialized overload signature is not assignable to any non-specialized signature.
29+
function hasKind(entity: Entity, kind: Kind): entity is (A | B) {
30+
return entity.kind === kind;
31+
}
32+
33+
let x: A = {
34+
kind: "A",
35+
a: 100,
36+
}
37+
38+
if (hasKind(x, "A")) {
39+
let a = x;
40+
}
41+
else {
42+
let b = x;
43+
}
44+
45+
if (!hasKind(x, "B")) {
46+
let c = x;
47+
}
48+
else {
49+
let d = x;
50+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//// [stringLiteralTypesAsTags02.ts]
2+
3+
type Kind = "A" | "B"
4+
5+
interface Entity {
6+
kind: Kind;
7+
}
8+
9+
interface A extends Entity {
10+
kind: "A";
11+
a: number;
12+
}
13+
14+
interface B extends Entity {
15+
kind: "B";
16+
b: string;
17+
}
18+
19+
function hasKind(entity: Entity, kind: "A"): entity is A;
20+
function hasKind(entity: Entity, kind: "B"): entity is B;
21+
function hasKind(entity: Entity, kind: Kind): entity is (A | B) {
22+
return entity.kind === kind;
23+
}
24+
25+
let x: A = {
26+
kind: "A",
27+
a: 100,
28+
}
29+
30+
if (hasKind(x, "A")) {
31+
let a = x;
32+
}
33+
else {
34+
let b = x;
35+
}
36+
37+
if (!hasKind(x, "B")) {
38+
let c = x;
39+
}
40+
else {
41+
let d = x;
42+
}
43+
44+
//// [stringLiteralTypesAsTags02.js]
45+
function hasKind(entity, kind) {
46+
return entity.kind === kind;
47+
}
48+
var x = {
49+
kind: "A",
50+
a: 100
51+
};
52+
if (hasKind(x, "A")) {
53+
var a = x;
54+
}
55+
else {
56+
var b = x;
57+
}
58+
if (!hasKind(x, "B")) {
59+
var c = x;
60+
}
61+
else {
62+
var d = x;
63+
}
64+
65+
66+
//// [stringLiteralTypesAsTags02.d.ts]
67+
declare type Kind = "A" | "B";
68+
interface Entity {
69+
kind: Kind;
70+
}
71+
interface A extends Entity {
72+
kind: "A";
73+
a: number;
74+
}
75+
interface B extends Entity {
76+
kind: "B";
77+
b: string;
78+
}
79+
declare function hasKind(entity: Entity, kind: "A"): entity is A;
80+
declare function hasKind(entity: Entity, kind: "B"): entity is B;
81+
declare let x: A;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
//// [stringLiteralTypesAsTags03.ts]
2+
3+
type Kind = "A" | "B"
4+
5+
interface Entity {
6+
kind: Kind;
7+
}
8+
9+
interface A extends Entity {
10+
kind: "A";
11+
a: number;
12+
}
13+
14+
interface B extends Entity {
15+
kind: "B";
16+
b: string;
17+
}
18+
19+
// Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid
20+
// interpreting respective overloads as "specialized" signatures.
21+
// That way, we can avoid the need to look for a compatible overload
22+
// signature and simply check compatibility with the implementation.
23+
function hasKind(entity: Entity, kind: "A" | "A"): entity is A;
24+
function hasKind(entity: Entity, kind: "B" | "B"): entity is B;
25+
function hasKind(entity: Entity, kind: Kind): entity is Entity {
26+
return entity.kind === kind;
27+
}
28+
29+
let x: A = {
30+
kind: "A",
31+
a: 100,
32+
}
33+
34+
if (hasKind(x, "A")) {
35+
let a = x;
36+
}
37+
else {
38+
let b = x;
39+
}
40+
41+
if (!hasKind(x, "B")) {
42+
let c = x;
43+
}
44+
else {
45+
let d = x;
46+
}
47+
48+
//// [stringLiteralTypesAsTags03.js]
49+
function hasKind(entity, kind) {
50+
return entity.kind === kind;
51+
}
52+
var x = {
53+
kind: "A",
54+
a: 100
55+
};
56+
if (hasKind(x, "A")) {
57+
var a = x;
58+
}
59+
else {
60+
var b = x;
61+
}
62+
if (!hasKind(x, "B")) {
63+
var c = x;
64+
}
65+
else {
66+
var d = x;
67+
}
68+
69+
70+
//// [stringLiteralTypesAsTags03.d.ts]
71+
declare type Kind = "A" | "B";
72+
interface Entity {
73+
kind: Kind;
74+
}
75+
interface A extends Entity {
76+
kind: "A";
77+
a: number;
78+
}
79+
interface B extends Entity {
80+
kind: "B";
81+
b: string;
82+
}
83+
declare function hasKind(entity: Entity, kind: "A" | "A"): entity is A;
84+
declare function hasKind(entity: Entity, kind: "B" | "B"): entity is B;
85+
declare let x: A;
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
=== tests/cases/conformance/types/stringLiteral/stringLiteralTypesAsTags03.ts ===
2+
3+
type Kind = "A" | "B"
4+
>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0))
5+
6+
interface Entity {
7+
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
8+
9+
kind: Kind;
10+
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18))
11+
>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0))
12+
}
13+
14+
interface A extends Entity {
15+
>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1))
16+
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
17+
18+
kind: "A";
19+
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 7, 28))
20+
21+
a: number;
22+
>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 8, 14))
23+
}
24+
25+
interface B extends Entity {
26+
>B : Symbol(B, Decl(stringLiteralTypesAsTags03.ts, 10, 1))
27+
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
28+
29+
kind: "B";
30+
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 12, 28))
31+
32+
b: string;
33+
>b : Symbol(b, Decl(stringLiteralTypesAsTags03.ts, 13, 14))
34+
}
35+
36+
// Currently (2015-12-14), we write '"A" | "A"' and '"B" | "B"' to avoid
37+
// interpreting respective overloads as "specialized" signatures.
38+
// That way, we can avoid the need to look for a compatible overload
39+
// signature and simply check compatibility with the implementation.
40+
function hasKind(entity: Entity, kind: "A" | "A"): entity is A;
41+
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63))
42+
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 21, 17))
43+
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
44+
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 21, 32))
45+
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 21, 17))
46+
>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1))
47+
48+
function hasKind(entity: Entity, kind: "B" | "B"): entity is B;
49+
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63))
50+
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 22, 17))
51+
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
52+
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 22, 32))
53+
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 22, 17))
54+
>B : Symbol(B, Decl(stringLiteralTypesAsTags03.ts, 10, 1))
55+
56+
function hasKind(entity: Entity, kind: Kind): entity is Entity {
57+
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63))
58+
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17))
59+
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
60+
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 23, 32))
61+
>Kind : Symbol(Kind, Decl(stringLiteralTypesAsTags03.ts, 0, 0))
62+
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17))
63+
>Entity : Symbol(Entity, Decl(stringLiteralTypesAsTags03.ts, 1, 21))
64+
65+
return entity.kind === kind;
66+
>entity.kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18))
67+
>entity : Symbol(entity, Decl(stringLiteralTypesAsTags03.ts, 23, 17))
68+
>kind : Symbol(Entity.kind, Decl(stringLiteralTypesAsTags03.ts, 3, 18))
69+
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 23, 32))
70+
}
71+
72+
let x: A = {
73+
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
74+
>A : Symbol(A, Decl(stringLiteralTypesAsTags03.ts, 5, 1))
75+
76+
kind: "A",
77+
>kind : Symbol(kind, Decl(stringLiteralTypesAsTags03.ts, 27, 12))
78+
79+
a: 100,
80+
>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 28, 14))
81+
}
82+
83+
if (hasKind(x, "A")) {
84+
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63))
85+
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
86+
87+
let a = x;
88+
>a : Symbol(a, Decl(stringLiteralTypesAsTags03.ts, 33, 7))
89+
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
90+
}
91+
else {
92+
let b = x;
93+
>b : Symbol(b, Decl(stringLiteralTypesAsTags03.ts, 36, 7))
94+
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
95+
}
96+
97+
if (!hasKind(x, "B")) {
98+
>hasKind : Symbol(hasKind, Decl(stringLiteralTypesAsTags03.ts, 15, 1), Decl(stringLiteralTypesAsTags03.ts, 21, 63), Decl(stringLiteralTypesAsTags03.ts, 22, 63))
99+
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
100+
101+
let c = x;
102+
>c : Symbol(c, Decl(stringLiteralTypesAsTags03.ts, 40, 7))
103+
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
104+
}
105+
else {
106+
let d = x;
107+
>d : Symbol(d, Decl(stringLiteralTypesAsTags03.ts, 43, 7))
108+
>x : Symbol(x, Decl(stringLiteralTypesAsTags03.ts, 27, 3))
109+
}

0 commit comments

Comments
 (0)