The conventions are integral part of the ts-essentials library codebase: they provide a consistent way of development for both maintainers and engineers that use this library.
Consistent naming improves readability and simplifies the maintainability.
Prefixes:
Any*
prefix is used for top types for specified subset of types, e.g.AnyFunction<Args?, ReturnType?>
for any possible functions,AnyArray<Type?>
for any type of arrays, etc.⚠️ NonEmptyArray<Type>
doesn't follow this rule and has to be renamed toAnyNonEmptyArray
Deep*
prefix is used when the type changes are applied to the whole structure recursively.- If you wonder why
Buildable<Type>
doesn't include a prefix, it is because it doesn't have direct recursive call
- If you wonder why
Is*
prefix is used when type expects to returntrue
orfalse
⚠️ Some types don't follow this convention for performance reasons, e.g.IsTuple<Type>
⚠️ Exact<Type, Shape>
returnType
ornever
and has to be updated toIsExact
to match the name of respective function calledisExact
Mark*
prefix is used when the partial type changes are applied to a type, e.g. some properties are set to optional inMarkOptional<Type, Keys>
Non*
prefix is used when type expects to returnType
ornever
(although this is not strict)NonNever<Type>
doesn't returnnever
so has to be renamed toOmitNeverProperties
Strict*
prefix is used when the additional generic constraint is applied to a type parameter to constrain its usage, e.g.StrictOmit<Type, Keys>
adds an additional generic constraint forKeys extends keyof Type
so only existing keys withinType
are passed to this utility type.⚠️ Inevitably allStrict*
types lack the support of generic types for the first type parameterType
because generic constraints rely on a structure ofType
which cannot be inferred at declaration. To mitigate it, please use non-Strict*
analogue of a utility type.
Body:
*Or*
is used for top types for 2 types, e.g.AsyncOrSync<Type>
for either asynchronous type (i.e.PromiseLike
) or a synchronous type.AsyncOrSyncType<Type>
is an exception because it serves to unwrapType
inAsyncOrSync<Type>
.
Suffices:
*Keys
suffix is used when the names of the properties (i.e. the keys) are returned or manipulated*Properties
suffix is used when the values of the properties (or simply properties) are returned or manipulatedNonNever<Type>
updates properties so has to be renamed toOmitNeverProperties