1 | /**
|
2 | 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 aide with assignability.
|
3 |
|
4 | This type is **experimental** and was introduced as a result of this {@link https://github.com/sindresorhus/type-fest/issues/436 issue}. It should be used with caution.
|
5 |
|
6 | @internal
|
7 | @experimental
|
8 | @see Simplify
|
9 | @category Object
|
10 | */
|
11 | export type ConditionalSimplify<Type, ExcludeType = never, IncludeType = unknown> = Type extends ExcludeType
|
12 | ? Type
|
13 | : Type extends IncludeType
|
14 | ? {[TypeKey in keyof Type]: Type[TypeKey]}
|
15 | : Type;
|
16 |
|
17 | /**
|
18 | Recursively simplifies a type while including and/or excluding certain types from being simplified.
|
19 |
|
20 | This type is **experimental** and was introduced as a result of this {@link https://github.com/sindresorhus/type-fest/issues/436 issue}. It should be used with caution.
|
21 |
|
22 | See {@link ConditionalSimplify} for usages and examples.
|
23 |
|
24 | @internal
|
25 | @experimental
|
26 | @category Object
|
27 | */
|
28 | export type ConditionalSimplifyDeep<Type, ExcludeType = never, IncludeType = unknown> = Type extends ExcludeType
|
29 | ? Type
|
30 | : Type extends IncludeType
|
31 | ? {[TypeKey in keyof Type]: ConditionalSimplifyDeep<Type[TypeKey], ExcludeType, IncludeType>}
|
32 | : Type;
|