-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutility-types.ts
More file actions
29 lines (26 loc) · 910 Bytes
/
utility-types.ts
File metadata and controls
29 lines (26 loc) · 910 Bytes
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
/**
* Primitive represents the basic types
*/
export type Primitive = string | number | boolean | Date | null | undefined;
/**
* CheckCircularly is a utility type that checks if a type is the same as its parent.
* If it is, it returns `never`, effectively breaking the circular reference.
*/
export type CheckCircularly<Type, Parent> = Type extends Parent ? never : Type;
/**
* ArrayType is a conditional type in TypeScript that extracts the type of the elements of an array.
*
* @template T The type to check. It should be an array type.
*
* @returns
** If T is an array type, it returns the type of the elements of the array.
** If T is not an array type, it returns T.
*
* @example
* type NumberType = ArrayType<number[]>;
* // ^? number
*
* type NumberType = ArrayType<number>;
* // ^? number
*/
export type ArrayType<T> = T extends (infer U)[] ? U : T;