UNPKG

666 BTypeScriptView Raw
1/**
2Returns a boolean for whether the given type is `any`.
3
4@link https://stackoverflow.com/a/49928360/1490091
5
6Useful in type utilities, such as disallowing `any`s to be passed to a function.
7
8@example
9```
10import type {IsAny} from 'type-fest';
11
12const typedObject = {a: 1, b: 2} as const;
13const anyObject: any = {a: 1, b: 2};
14
15function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
16 return obj[key];
17}
18
19const typedA = get(typedObject, 'a');
20//=> 1
21
22const anyA = get(anyObject, 'a');
23//=> any
24```
25
26@category Type Guard
27@category Utilities
28*/
29export type IsAny<T> = 0 extends 1 & T ? true : false;