Skip to content

Commit 5e23143

Browse files
Accepted baselines.
1 parent bf4880a commit 5e23143

8 files changed

+277
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts(6,9): error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'.
2+
tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts(9,14): error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'.
3+
4+
5+
==== tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts (2 errors) ====
6+
7+
type S = "a" | "b";
8+
type T = S[] | S;
9+
10+
function f(foo: T) {
11+
if (foo === "a") {
12+
~~~~~~~~~~~
13+
!!! error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'.
14+
return foo;
15+
}
16+
else if (foo === "b") {
17+
~~~~~~~~~~~
18+
!!! error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'.
19+
return foo;
20+
}
21+
else {
22+
return (foo as S[])[0];
23+
}
24+
25+
throw new Error("Unreachable code hit.");
26+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [stringLiteralCheckedInIf01.ts]
2+
3+
type S = "a" | "b";
4+
type T = S[] | S;
5+
6+
function f(foo: T) {
7+
if (foo === "a") {
8+
return foo;
9+
}
10+
else if (foo === "b") {
11+
return foo;
12+
}
13+
else {
14+
return (foo as S[])[0];
15+
}
16+
17+
throw new Error("Unreachable code hit.");
18+
}
19+
20+
//// [stringLiteralCheckedInIf01.js]
21+
function f(foo) {
22+
if (foo === "a") {
23+
return foo;
24+
}
25+
else if (foo === "b") {
26+
return foo;
27+
}
28+
else {
29+
return foo[0];
30+
}
31+
throw new Error("Unreachable code hit.");
32+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf02.ts(6,12): error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'.
2+
tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf02.ts(6,25): error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'.
3+
4+
5+
==== tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf02.ts (2 errors) ====
6+
7+
type S = "a" | "b";
8+
type T = S[] | S;
9+
10+
function isS(t: T): t is S {
11+
return t === "a" || t === "b";
12+
~~~~~~~~~
13+
!!! error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'.
14+
~~~~~~~~~
15+
!!! error TS2365: Operator '===' cannot be applied to types '("a" | "b")[] | "a" | "b"' and 'string'.
16+
}
17+
18+
function f(foo: T) {
19+
if (isS(foo)) {
20+
return foo;
21+
}
22+
else {
23+
return foo[0];
24+
}
25+
26+
throw new Error("Unreachable code hit.");
27+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//// [stringLiteralCheckedInIf02.ts]
2+
3+
type S = "a" | "b";
4+
type T = S[] | S;
5+
6+
function isS(t: T): t is S {
7+
return t === "a" || t === "b";
8+
}
9+
10+
function f(foo: T) {
11+
if (isS(foo)) {
12+
return foo;
13+
}
14+
else {
15+
return foo[0];
16+
}
17+
18+
throw new Error("Unreachable code hit.");
19+
}
20+
21+
//// [stringLiteralCheckedInIf02.js]
22+
function isS(t) {
23+
return t === "a" || t === "b";
24+
}
25+
function f(foo) {
26+
if (isS(foo)) {
27+
return foo;
28+
}
29+
else {
30+
return foo[0];
31+
}
32+
throw new Error("Unreachable code hit.");
33+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
tests/cases/conformance/types/stringLiteral/stringLiteralMatchedInSwitch01.ts(7,10): error TS2322: Type 'string' is not assignable to type '("a" | "b")[] | "a" | "b"'.
2+
Type 'string' is not assignable to type '"b"'.
3+
tests/cases/conformance/types/stringLiteral/stringLiteralMatchedInSwitch01.ts(8,10): error TS2322: Type 'string' is not assignable to type '("a" | "b")[] | "a" | "b"'.
4+
Type 'string' is not assignable to type '"b"'.
5+
6+
7+
==== tests/cases/conformance/types/stringLiteral/stringLiteralMatchedInSwitch01.ts (2 errors) ====
8+
9+
type S = "a" | "b";
10+
type T = S[] | S;
11+
12+
var foo: T;
13+
switch (foo) {
14+
case "a":
15+
~~~
16+
!!! error TS2322: Type 'string' is not assignable to type '("a" | "b")[] | "a" | "b"'.
17+
!!! error TS2322: Type 'string' is not assignable to type '"b"'.
18+
case "b":
19+
~~~
20+
!!! error TS2322: Type 'string' is not assignable to type '("a" | "b")[] | "a" | "b"'.
21+
!!! error TS2322: Type 'string' is not assignable to type '"b"'.
22+
break;
23+
default:
24+
foo = (foo as S[])[0];
25+
break;
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [stringLiteralMatchedInSwitch01.ts]
2+
3+
type S = "a" | "b";
4+
type T = S[] | S;
5+
6+
var foo: T;
7+
switch (foo) {
8+
case "a":
9+
case "b":
10+
break;
11+
default:
12+
foo = (foo as S[])[0];
13+
break;
14+
}
15+
16+
//// [stringLiteralMatchedInSwitch01.js]
17+
var foo;
18+
switch (foo) {
19+
case "a":
20+
case "b":
21+
break;
22+
default:
23+
foo = foo[0];
24+
break;
25+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(22,5): error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other.
2+
Type 'string' is not assignable to type '"b"'.
3+
tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(23,5): error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other.
4+
Type 'string' is not assignable to type '"b"'.
5+
tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(30,7): error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other.
6+
Type '("a" | "b")[]' is not assignable to type 'string'.
7+
tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts(31,7): error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other.
8+
Type '("a" | "b")[]' is not assignable to type 'string'.
9+
10+
11+
==== tests/cases/conformance/types/stringLiteral/stringLiteralTypeAssertion01.ts (4 errors) ====
12+
13+
type S = "a" | "b";
14+
type T = S[] | S;
15+
16+
var s: S;
17+
var t: T;
18+
var str: string;
19+
20+
////////////////
21+
22+
s = <S>t;
23+
s = t as S;
24+
25+
s = <S>str;
26+
s = str as S;
27+
28+
////////////////
29+
30+
t = <T>s;
31+
t = s as T;
32+
33+
t = <T>str;
34+
~~~~~~
35+
!!! error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other.
36+
!!! error TS2352: Type 'string' is not assignable to type '"b"'.
37+
t = str as T;
38+
~~~~~~~~
39+
!!! error TS2352: Neither type 'string' nor type '("a" | "b")[] | "a" | "b"' is assignable to the other.
40+
!!! error TS2352: Type 'string' is not assignable to type '"b"'.
41+
42+
////////////////
43+
44+
str = <string>s;
45+
str = s as string;
46+
47+
str = <string>t;
48+
~~~~~~~~~
49+
!!! error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other.
50+
!!! error TS2352: Type '("a" | "b")[]' is not assignable to type 'string'.
51+
str = t as string;
52+
~~~~~~~~~~~
53+
!!! error TS2352: Neither type '("a" | "b")[] | "a" | "b"' nor type 'string' is assignable to the other.
54+
!!! error TS2352: Type '("a" | "b")[]' is not assignable to type 'string'.
55+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//// [stringLiteralTypeAssertion01.ts]
2+
3+
type S = "a" | "b";
4+
type T = S[] | S;
5+
6+
var s: S;
7+
var t: T;
8+
var str: string;
9+
10+
////////////////
11+
12+
s = <S>t;
13+
s = t as S;
14+
15+
s = <S>str;
16+
s = str as S;
17+
18+
////////////////
19+
20+
t = <T>s;
21+
t = s as T;
22+
23+
t = <T>str;
24+
t = str as T;
25+
26+
////////////////
27+
28+
str = <string>s;
29+
str = s as string;
30+
31+
str = <string>t;
32+
str = t as string;
33+
34+
35+
//// [stringLiteralTypeAssertion01.js]
36+
var s;
37+
var t;
38+
var str;
39+
////////////////
40+
s = t;
41+
s = t;
42+
s = str;
43+
s = str;
44+
////////////////
45+
t = s;
46+
t = s;
47+
t = str;
48+
t = str;
49+
////////////////
50+
str = s;
51+
str = s;
52+
str = t;
53+
str = t;

0 commit comments

Comments
 (0)