mirror of
https://github.com/swc-project/swc.git
synced 2024-12-01 01:13:56 +03:00
16 lines
216 B
TypeScript
16 lines
216 B
TypeScript
|
|
type S = "a" | "b";
|
|
type T = S[] | S;
|
|
|
|
function isS(t: T): t is S {
|
|
return t === "a" || t === "b";
|
|
}
|
|
|
|
function f(foo: T) {
|
|
if (isS(foo)) {
|
|
return foo;
|
|
}
|
|
else {
|
|
return foo[0];
|
|
}
|
|
} |