Decorated property accessor type.
Defines the type that the decorated accessor property name extends.
Decorated accessor property class' prototype (for instance accessor) or constructor function (for static accessor).
Name of the decorated property accessor.
Descriptor of the decorated property accessor.
If the accessor decorator returns a value, it will be used as the Property Descriptor for the member.
When targeting versions less than ES5 propDescriptor will be undefined
and the return value is ignored.
See https://www.typescriptlang.org/docs/handbook/decorators.html#accessor-decorators
Defines true if T1 is exactly T2, false otherwise.
Even AreSame<unknown, any> expands to false. Only the same types expand to true.
Beware that this type works as vanilla extends clause with function types,
so comparing functions is not that strict.
Type to strictly compare to T2.
Type to strictly compare to T1.
Defines an asyncronous function, which is typically marked with async modifier,
with arguments specified as a tuple type TArgs and return type as Promise<TRet>.
Tuple type of arguments that defined async function accepts.
Type this function returns Promise for.
Type of this function context.
Defines the unpacked result type of the Promise returned by the specified AsyncFunc.
AsyncFunc to unpack Promise return type from.
Defines an asyncronous function, which is typically marked with async modifier,
with arguments specified as a tuple type TArgs and return type as Promise<unknown>.
Tuple type of arguments that defined async function accepts.
Type this function context.
Defines boolean type opeartor tree type. E.g.
import { Op } from 'ts-typedefs';
type ExampleBoolOp = Op.Or<
Op.If< Op.UnionIncludes<number | string>,
Not<Op.Extends<boolean>>,
false
>,
Op.Extends<null>
>;
Defines true if TSuspect contains null, false otherwise.
As a special case, defines true when TSuspect is unknown or any,
false if TSuspect is never.
Defines true if TSuspect contains undefined, false otherwise.
As a special case, defines true when TSuspect is unknown or any,
false if TSuspect is never.
Defines constructor function type.
Type of instances produced by this constructor.
Tuple type of arguments, this constructor accepts.
Defines a class decorator generic function type.
Target class constructor function type.
Decorated class constructor function.
If the class decorator returns a value, it will replace the class declaration with the provided constructor function.
See https://www.typescriptlang.org/docs/handbook/decorators.html#-decorators
Defines constructor function prototype property type.
Target constructor function type.
Defines the same object type as TSrcObj, but all values types
replaced with TMappedValue type recursively.
Type of object to take keys from.
Type of values in the created object type.
Defines the same type as TObj but with readonly modifier removed from its properties recursively.
Target object type to make its properties recursively mutable.
Defines the same type as TObj but with all properties made NonNullable<> recursively.
Target object type to make its properties recursively non-nullable.
Defines the same type as TObj but with all properties made Nullable<> recursively.
Target object type to make its properties recursively nullable.
Defines the same type as TObj but all properties are made recursively Partial<>.
Object type to make all properties optional.
Defines the same type as TObj but with readonly modifier added to its properties recursively.
Target object type to make its properties recursively readonly.
Defines the same type as TObj but all properties are made recursively Required<>.
Object type to remove optional ? flag from.
Defines a Widen<>ed version of TObj with all its values widened recursively.
See Widen
Target object (including tuple) type to widen recursively.
Defines true or false by applying the given
TOp operator object tree to the given TParam.
BoolOp operator tree to apply to TParam.
Value of any type to pipe through BoolOp.
Because of some TypeScript limitations and bugs (https://stackoverflow.com/questions/55192212/typescript-circular-type-alias-produces-no-error-and-instead-widens-unit-types)
BoolOp tree must be not more than 4 levels deep.
Defines the same type as TObj but with particular properties filtered out
according to TApproveCond.
Target object type to filter properties from.
Op.BoolOp type that gets evaluated for each property of TObj.
If Eval<TApproveCond, TObj[TKey]> === false
TKey will be filtered out.
Defines a union of property names taken from TObj according to the given TApproveCond.
Target object type to filter properties from.
Op.BoolOp type that gets evaluated for each property of TObj.
If Eval<TApproveCond, TObj[TKey]> === true
TKey will be present in the resulting union .
Defines a function type with the given arguments, return value and this context.
Tuple of argument types that defined function accepts.
Type of value this function returns.
Type of this function context.
Defines typeof this that the given TFunc must be run with.
Function type to infer this context type from.
Defines an instance type of the given class or the type of prototype property
of the given Prototypeful object. TClass may even be an abstract class,
though those ones are not newable, but the type of their instances can be obtained
through their prototype property.
Abstract or plain class/interface to unpack instance type from.
Defines true if TSuspect is exactly of any type, false otherwise.
Target type to check.
Shorthand for Extends<TSuspect, AsyncFunc>.
Target type to check.
Shorthand for Extends<TSuspect, Func>.
Target type to check.
Defines true if TSuspect is exactly of never type, false otherwise.
Target type to check.
Defines false if TSuspect is exactly of any type, true otherwise.
Target type to check.
Defines false if TSuspect is exactly of never type, true otherwise.
Target type to check.
Defines false if TSuspect is exactly of unknown type, true otherwise.
Target type to check.
Defines true if TSuspect contains both undefined and null types, false otherwise.
As a special case, defines true when TSuspect is unknown or any,
false if TSuspect is never.
Target type to check
Defines true if TSuspect is exactly of unknown type, false otherwise.
Target type to check.
Defines the same object type as TSrcObj, but all values types
replaced with TMappedValue type.
Type of object to take keys from.
Type of values in the created object type.
Merge objects TObj1 and TObj2.
Properties types from TObj2 override the ones defined on TObj1.
This type is analogous to the return type of Object.assign()
Defines a type that is the same as TClass[TMethodName], but restricts this
context to be of type TClass. This is usefull when you want to create proxies
for some methods and have this type being automatically set to TClass in their bodies,
so that compiler won't this is implicit any error and you don't have to type this
manually.
Class instance type to take method from (also becomes this type).
Keyof TClass that defines the method name to take from TClass.
Defines a static or instance method decorator function type.
Tuple type that defines arguments decorated method accepts.
Return type of the decorated method.
Defines the type that the decorated method name extends.
Prototype of the decorated method's class (for instance method) or constructor function (for static method).
Name of the property, that contains decorated method.
Descriptor of the decorated method property.
Decorated function this context is of typeof protoOrClass type.
If the method decorator returns a value, it will be used as the Property Descriptor for the method.
When targeting versions less than ES5 methodDescriptor will be undefined
and the return value is ignored.
See https://www.typescriptlang.org/docs/handbook/decorators.html#method-decorators
Defines the same type as TObj but with readonly modifier removed from its TKeys.
Object type to make TKeys mutable in.
Union type of keys that will be defined as mutable in the resulting type.
Defines a discriminated union of two object types. This simply means that
when properties of A are present in the value shape all the properties of
B must be undefined and vice versa.
The resulting type ensures that the properties of only one object type (A or B) are
present in the resulting object shape with all other properties of the second
object type being undefined via the special handling of unit type properties
in TypeScript object unions.
In this case the discriminator of the union is the unit type undefined.
// Properties "a" and "c" on foo may not coexist, one of them must be undefined.
// Type of property "b" depends on the active object shape (it may be either
// number or string)
type Foo = MutuallyExclusive<{ a: string, b: string }, { b: number, c: boolean }>;
declare const val: Foo;
if (val.a == null) {
val; // { a?: undefined, b: number, c: boolean }
} else {
val; // { a: string, b: string, c?: undefined }
}
Defines the same type as TObj but with TKeys made non-nullable (and required).
Object type to make TKeys non-nullable in.
Union type of keys that will be defined as non-nullable in the resulting type.
Shorthand for Op.Not<Op.Extends<TExtendee>>.
Shorthand for Not<Extends<>>.
Defines type T that may also be null or undefined.
Target type to make "nullable".
Defines the same type as TObj but with TKeys made nullable (and optional).
Object type to make TKeys nullable in.
Union type of keys that will be defined as nullable in the resulting type.
Defines an object with keys of type TKey, and all values of TValue type.
Type of values, stored in object's properties.
Union type of keys stored in defined object type.
It is any by default, if you use this parameter,
most probably you will specify a union of some string or number unit types.
Defines the same type as TObj, but adds 'optional' modifier ? to all
properties that allow undefined as their value type (this includes unknown and any).
Target object type to take properties from.
Defines a static or instance method parameter decorator function type.
Type parameter TParamType is an experimental feature and it won't work
untill the following issue is solved https://github.com/Microsoft/TypeScript/issues/30102
Type of the parameter this decorator may be applied to.
Decorated method parameter class' prototype (for instance method) or constructor function (for static method).
Name of the decorated parameter's method.
The ordinal index of the parameter in the function’s parameter list.
Return value is totally ignored.
See https://www.typescriptlang.org/docs/handbook/decorators.html#parameter-decorators
Defines the same type as TObj but with TKeys made optional.
Object type to make TKeys optional in.
Union type of keys that will be defined as optional in the resulting type.
Shorthand for Mutable<Pick<TObj, TKeys>>, but better optimized (into one mapped object type).
Object type to pick properties from.
Union type of keys to pick.
Shorthand for NonNullableProps<Pick<TObj, TKeys>>, but better optimized (into one mapped object type).
Object type to pick properties from.
Union type of keys to pick.
Shorthand for NullableProps<Pick<TObj, TKeys>>, but better optimized (into one mapped object type).
Object type to pick properties from.
Union type of keys to pick.
Shorthand for Partial<Pick<TObj, TKeys>>, but better optimized (into one mapped object type).
Object type to pick properties from.
Union type of keys to pick.
Shorthand for Readonly<Pick<TObj, TKeys>>, but better optimized (into one mapped object type).
Object type to pick properties from.
Union type of keys to pick.
Shorthand for Required<Pick<TObj, TKeys>>, but better optimized (into one mapped object type).
Object type to pick properties from.
Union type of keys to pick.
Defines a union of all possible value types defined in the language.
null and undefined are considered to be primitive types.
Defines a static or instance property decorator function type.
Decorated property type.
Defines the type that the decorated property name extends.
Decorated property class' prototype (for instance property) or constructor function (for static property).
Name of the decorated property.
Return value is totally ignored.
See https://www.typescriptlang.org/docs/handbook/decorators.html#property-decorators
Defines the same type as TObj but with TKeys made readonly.
Object type to make TKeys readonly in.
Union type of keys that will be defined as readonly in the resulting type.
Same as BasicObject<>, but defines all properties as readonly.
Type of values, stored in object's readonly properties.
Defines the same object type as TSrcObj, but without TKeysUnion keys.
Type of object to remove keys from.
A single or union type of keys to remove from TSrcObj.
Defines the same object type as TObj, but with TPrevKey key renamed to TNewKey.
Object type to rename key in.
Target property key to rename.
New name (or symbol) for the TObj[TPrevKey] property.
Defines the same object type as TSrcObj, but with TKeys keys
having the value of type TNewValue.
Type of object to replace property type of.
Union type of keys to change value types of (often just a string literal).
Type of values stored at TKeys keys in the returned type.
Defines the same type as TObj but with TKeys made required.
Object type to make TKeys required in.
Union type of keys that will be defined as required in the resulting type.
Defines a function type with the given arguments, and this context.
Return value of the defined function type is void.
Tuple of argument types that this function accepts.
Type this function context.
Shorthand for Extract<keyof TObj, string>, i.e. it gets only those keys
that are assignable to string (without number | symbol)
Objet type to get string keys from.
Defines a function type with the given arguments and this context.
Defined function may return TRet synchronously or asynchronously i.e.
Promise<TRet>.
Tuple of argument types that defined function accepts.
Type of value this function returns.
Type of this function context.
Defines a function type with the given arguments and this context.
Defined function may return synchronously or asynchronously. Its return value
should be ignored (it is void | Promise<unknown>).
Tuple of argument types that defined function accepts.
Type of this function context.
Defines nominal type by adding a property with TTagName value to TTarget.
TTagName must be unique across your application, treat it like the name of
your nominal type.
Target type to put a tag on.
Unique name of the defined nominal type.
With this type, you may pick particular subclass of values from the given type and force
your clients to filter other values that are assignable to TTarget but don't
obey to your prerequisites, thus making them pay more attention to them.
import { Tag } from 'ts-typedefs';
// Number value that is strictly grater than zero.
type PositiveInt = Tag<number, 'PositiveInt'>;
// Represents valid csv string.
type CsvString = Tag<string, 'CsvString'>;
async function getUser(userId: PositiveInt) {
return userRepository.findById(userId);
}
function parseCsv(csvString: CsvString) {
// Here you may be sure that client payed attention to checking the input
const lines = csvString.split('\n').map(line => line.split(','));
}
getUser(-2); // compile error
getUser(58); // compile error
getUser(58 as PositiveInt); // fine (explicit cast pays your attention to prerequisites)
parseCsv('\nbla bla'); // compile error
parseCsv('a,b,c\nd,e,f' as CsvString); // fine
Defines tuple type of TItems union type values.
Union type of items of the defined tuple.
Shorthand for TTuple[0].
Target tuple to get first item from.
Defines the type of the last item in TTuple.
If TTuple is empty, then expands to undefined.
Target tuple to get last item from.
Removes the last item from TTuple. Does nothing if tuple is empty.
Tuple to remove last item from.
Pushes TNewLastItem item to the back of TTuple.
Tuple to push TNewLastItem to the back.
Item type to push to the back of TTuple.
Removes the first item from TTuple. Does nothing if tuple is empty.
Tuple to remove first item from.
Widens [T1, T2, T3, ...] tuple type into an array type (T1 | T2 | T3 | ...)[]
Tuple type to widen to array.
Pushes TNewFirstItem item to the front of TTuple.
Tuple to push TNewFirstItem to the front.
Item type to push to the front of TTuple.
Defines a union of all possible strings retuned by applying typeof operator.
Defines type predicate function, i.e. a function that takes suspect of unknown type
and returns a boolean that denotes whether suspect is of TTarget type or not.
Type that this predicate checks suspect to conform to.
Type of this context of the predicate.
Shorthand for Op.Not<Op.UnionIncludes<TNeedle>>.
Defines false if the given TUnion includes TValue.
This type is opposite to UnionIncludes<>.
Union type to search for TValue in.
Type to match with TUnion members.
Defines the type of values of the given TArray
Type of array to infer items type from.
Defines the type of value, which is passed to TPromise.then(cb) cb callback.
Target Promise to unpack result from.
Defines a type that the given TTypePred checks its suspect to conform to.
Target TypePredicate function to unpack.
Defines a union type of all the values stored in TObj.
Object type to get values from.
Defines string or number or boolean or Array<T[number]> that represents
a widened contravariant version of the given unit type T.
Unit type to widen.
T is a tuple type it is widened to Array<> type.T is string or number literal or true or false it gets widened to
string or number or boolean respectivelly.T is not a unit type, it is left as it is.C++ style operator, a syntactic sugar for writing casts like
value as any as T when a simple value as T cast cannot be performed.
Use it with caution!
Defines a static or instance get/set property accessor decorator function type.