generated from garronej/ts-ci
-
Notifications
You must be signed in to change notification settings - Fork 6
/
is.ts
28 lines (21 loc) 路 745 Bytes
/
is.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
/* eslint-disable @typescript-eslint/no-namespace */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { assertIsRefWrapper } from "./zz_internal/assertIsRefWrapper.ts";
const errorMessage = [
`Wrong usage of the ${is.name} function refer to`,
`https://docs.tsafe.dev/${is.name.toLowerCase()}`,
].join(" ");
export function is<T>(_value: any): _value is T {
const ref = {};
if (assertIsRefWrapper.ref !== undefined) {
assertIsRefWrapper.ref = undefined;
throw new Error(errorMessage);
}
assertIsRefWrapper.ref = ref;
Promise.resolve().then(() => {
if (assertIsRefWrapper.ref === ref) {
throw new Error(errorMessage);
}
});
return null as any;
}