UNPKG

1.28 kBTypeScriptView Raw
1/**
2Simplifies 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
4This 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*/
11export 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/**
18Recursively simplifies a type while including and/or excluding certain types from being simplified.
19
20This 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
22See {@link ConditionalSimplify} for usages and examples.
23
24@internal
25@experimental
26@category Object
27*/
28export 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;