generated from garronej/ts-ci
/
assertIs.ts
49 lines (34 loc) 路 825 Bytes
/
assertIs.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
48
49
/* eslint-disable @typescript-eslint/no-explicit-any */
import { assert } from "../assert.ts";
import { is } from "../is.ts";
import type { Equals } from "../Equals.ts";
{
const x: string | number | boolean = null as any;
assert(is<string>(x));
assert<Equals<typeof x, string>>();
console.log("PASS");
}
{
const x: string | number | boolean = null as any;
assert(!is<string>(x));
assert<Equals<typeof x, number | boolean>>();
console.log("PASS");
}
{
is<unknown>(null);
try {
is<unknown>(null);
throw new Error("FAIL");
// eslint-disable-next-line no-empty
} catch {}
console.log("PASS");
}
scope: {
try {
assert(undefined);
} catch {
console.log("PASS");
break scope;
}
throw new Error("Fail");
}