-
-
Notifications
You must be signed in to change notification settings - Fork 677
Expand file tree
/
Copy pathconditional-simplify.d.ts
More file actions
50 lines (37 loc) · 1.17 KB
/
conditional-simplify.d.ts
File metadata and controls
50 lines (37 loc) · 1.17 KB
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
50
/**
Simplifies a type while including and/or excluding certain types from being simplified.
Useful to improve type hints shown in editors. And also to transform an `interface` into a `type` to aid with assignability.
@example
```
import type {ConditionalSimplify} from 'type-fest';
type TypeA = {
a: string;
};
type TypeB = {
b: string;
};
type TypeAB = TypeA & TypeB;
//=> TypeA & TypeB
type SimplifyTypeAB = ConditionalSimplify<TypeAB, never, object>;
//=> {a: string; b: string}
```
@example
```
import type {ConditionalSimplify} from 'type-fest';
type Simplify<T> = ConditionalSimplify<T, Set<unknown> | Map<unknown, unknown> | unknown[], object>;
type A = Simplify<Set<number> & Set<string>>;
//=> Set<number> & Set<string>
type B = Simplify<Map<number, number> & Map<string, string>>;
//=> Map<number, number> & Map<string, string>
type C = Simplify<{a: number} & {b: string}>;
//=> {a: number; b: string}
```
@see {@link ConditionalSimplifyDeep}
@category Object
*/
export type ConditionalSimplify<Type, ExcludeType = never, IncludeType = unknown> = Type extends ExcludeType
? Type
: Type extends IncludeType
? {[TypeKey in keyof Type]: Type[TypeKey]}
: Type;
export {};