mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
32 lines
572 B
TypeScript
32 lines
572 B
TypeScript
//// [tests/cases/conformance/types/stringLiteral/stringLiteralCheckedInIf01.ts] ////
|
|
|
|
//// [stringLiteralCheckedInIf01.ts]
|
|
type S = "a" | "b";
|
|
type T = S[] | S;
|
|
|
|
function f(foo: T) {
|
|
if (foo === "a") {
|
|
return foo;
|
|
}
|
|
else if (foo === "b") {
|
|
return foo;
|
|
}
|
|
else {
|
|
return (foo as S[])[0];
|
|
}
|
|
}
|
|
|
|
//// [stringLiteralCheckedInIf01.js]
|
|
"use strict";
|
|
function f(foo) {
|
|
if (foo === "a") {
|
|
return foo;
|
|
}
|
|
else if (foo === "b") {
|
|
return foo;
|
|
}
|
|
else {
|
|
return foo[0];
|
|
}
|
|
}
|