-
Notifications
You must be signed in to change notification settings - Fork 28
/
oneOf.test.ts
47 lines (42 loc) · 1004 Bytes
/
oneOf.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import oneOf from "./oneOf.ts";
import { assert } from "testing/asserts.ts";
Deno.test("oneOf", () => {
{
const unknown: unknown = 2;
assert(oneOf(unknown as any, 1, 2, 3));
if (oneOf(unknown, 1, 2, 3)) {
const _n: number = unknown;
} else {
// @ts-expect-error
const _n: number = unknown;
}
}
{
const unknown: unknown = "a";
assert(oneOf(unknown as any, 1, 2, "a", "b"));
if (oneOf(unknown, 1, 2, "a", "b")) {
const _sOrN: string | number = unknown;
} else {
// @ts-expect-error
const _sOrN: string | number = unknown;
}
}
{
const unknown: unknown = "foo";
if (oneOf(unknown, "foo", "bar")) {
const _known: "foo" | "bar" = unknown;
}
}
{
const unknown: unknown = 2;
if (oneOf(unknown, 1, 2)) {
const _known: 1 | 2 = unknown;
}
}
{
const unknown: unknown = 1;
if (oneOf(unknown, 1, 2, "a", "b")) {
const _known: 1 | 2 | "a" | "b" = unknown;
}
}
});