Skip to content

Commit d9672a6

Browse files
committed
string literal case test
1 parent 2d457fc commit d9672a6

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [typeGuardNarrowsToLiteralType.ts]
2+
declare function isFoo(value: string) : value is "foo";
3+
declare function doThis(value: "foo"): void;
4+
declare function doThat(value: string) : void;
5+
let value: string;
6+
if (isFoo(value)) {
7+
doThis(value);
8+
} else {
9+
doThat(value);
10+
}
11+
12+
13+
14+
//// [typeGuardNarrowsToLiteralType.js]
15+
var value;
16+
if (isFoo(value)) {
17+
doThis(value);
18+
}
19+
else {
20+
doThat(value);
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/conformance/expressions/typeGuards/typeGuardNarrowsToLiteralType.ts ===
2+
declare function isFoo(value: string) : value is "foo";
3+
>isFoo : Symbol(isFoo, Decl(typeGuardNarrowsToLiteralType.ts, 0, 0))
4+
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralType.ts, 0, 23))
5+
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralType.ts, 0, 23))
6+
7+
declare function doThis(value: "foo"): void;
8+
>doThis : Symbol(doThis, Decl(typeGuardNarrowsToLiteralType.ts, 0, 55))
9+
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralType.ts, 1, 24))
10+
11+
declare function doThat(value: string) : void;
12+
>doThat : Symbol(doThat, Decl(typeGuardNarrowsToLiteralType.ts, 1, 44))
13+
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralType.ts, 2, 24))
14+
15+
let value: string;
16+
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralType.ts, 3, 3))
17+
18+
if (isFoo(value)) {
19+
>isFoo : Symbol(isFoo, Decl(typeGuardNarrowsToLiteralType.ts, 0, 0))
20+
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralType.ts, 3, 3))
21+
22+
doThis(value);
23+
>doThis : Symbol(doThis, Decl(typeGuardNarrowsToLiteralType.ts, 0, 55))
24+
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralType.ts, 3, 3))
25+
26+
} else {
27+
doThat(value);
28+
>doThat : Symbol(doThat, Decl(typeGuardNarrowsToLiteralType.ts, 1, 44))
29+
>value : Symbol(value, Decl(typeGuardNarrowsToLiteralType.ts, 3, 3))
30+
}
31+
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
=== tests/cases/conformance/expressions/typeGuards/typeGuardNarrowsToLiteralType.ts ===
2+
declare function isFoo(value: string) : value is "foo";
3+
>isFoo : (value: string) => value is "foo"
4+
>value : string
5+
>value : any
6+
7+
declare function doThis(value: "foo"): void;
8+
>doThis : (value: "foo") => void
9+
>value : "foo"
10+
11+
declare function doThat(value: string) : void;
12+
>doThat : (value: string) => void
13+
>value : string
14+
15+
let value: string;
16+
>value : string
17+
18+
if (isFoo(value)) {
19+
>isFoo(value) : boolean
20+
>isFoo : (value: string) => value is "foo"
21+
>value : string
22+
23+
doThis(value);
24+
>doThis(value) : void
25+
>doThis : (value: "foo") => void
26+
>value : "foo"
27+
28+
} else {
29+
doThat(value);
30+
>doThat(value) : void
31+
>doThat : (value: string) => void
32+
>value : string
33+
}
34+
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
declare function isFoo(value: string) : value is "foo";
2+
declare function doThis(value: "foo"): void;
3+
declare function doThat(value: string) : void;
4+
let value: string;
5+
if (isFoo(value)) {
6+
doThis(value);
7+
} else {
8+
doThat(value);
9+
}
10+

0 commit comments

Comments
 (0)