/** * Make an interface nullable */ export type Nullable = { [P in keyof GType]: GType[P] | null }; /** * Remove keys from an interface */ export type Omit = Pick>; /** * Give keys the type never */ export type Never = Omit & Partial>; /** * Makes specified keys of an interface Optional. */ export type MakeOptional = Omit & { [P in GKeys]+?: GType[P] }; /** * Makes specified keys of an interface nullable. */ export type MakeNullable = Omit & { [P in GKeys]: GType[P] | null }; /** * Makes specified keys of an interface Required. */ export type MakeRequired = Omit & { [P in GKeys]-?: GType[P] }; /** * Makes specified keys of an interface readonly. */ export type MakeReadonly = Omit & { +readonly [P in GKeys]: GType[P] }; /* Helper Types */ /** * Get all property names from an interface which are functions. */ export type FunctionPropertyNames = { [K in keyof T]: T[K] extends AnyFunction ? K : never }[keyof T]; /** * Pick an interface composed entirely of the function properties. */ export type FunctionProperties = Pick>; /** * Get all property names from an interface which are not functions. */ export type NonFunctionPropertyNames = { [K in keyof T]: T[K] extends AnyFunction ? never : K }[keyof T]; /** * Pick an interface composed entirely of the non function properties. */ export type NonFunctionProperties = Pick>; /** * Pick the values from a type */ export type ValueOf = GType[keyof GType]; /** * Alias of @see ValueOf */ export type Value = ValueOf; export type Key = keyof GType; /** * Removes all types from a union that don't extend from the extender type */ export type Include = GType extends GExtender ? GType : never; export type ValueOfStringArray = Include], string>; /** * A union of all the type primitives (including the empty object) */ export type Literal = string | number | boolean | undefined | null | void | {}; /** * Pick the Nth Param for any function with the first parameter marked by the 0 index. */ export type NthParam = GFunction extends ( // tslint:disable-next-line:no-unused ...args: infer GArgs ) => any ? GArgs[GIndex] : never; /** * Use this to create a Tuple with args that can be used as a type * * @example * ``` * const ALL_SUITS = tuple('hearts', 'diamonds', 'spades', 'clubs'); * type SuitTuple = typeof ALL_SUITS; * type Suit = SuitTuple[number]; // union type * ``` * @param args */ export const tuple = (...args: GType) => args; /** * A useful helper for conditional types */ export type FilterFlags = { [P in keyof GBase]: GBase[P] extends GCondition ? P : never }; export type AnyFunction = (...args: any[]) => any; /** * Useful for removing the empty interface `{}` from a list of types */ export type NonEmptyInterface = keyof GType extends never ? never : GType; export type AnyKey = string | number | symbol;