export type ObjectId = string export type Env = 'test' | 'development' | 'production' | 'preprod' | 'build' | 'ci' export type MaybeArray = T | T[] export type MaybePromise = T | Promise export type HasKeys = keyof T extends never ? false : true export type FunctionGeneric = (...params: any[]) => any export type ObjectGeneric = { [k: string]: any } export type ObjectWithNoFn = { [name: string]: NotFunction } // eslint-disable-next-line @typescript-eslint/ban-types export type NotFunction = T extends Function ? never : T export type AsType = T extends Type ? T : Type export type AsString = AsType export type Complete = { [P in keyof Required]: T[P]; } export type Override = Omit & T2 export type RecursivePartial = { [P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial[] : T[P] extends object ? RecursivePartial : T[P]; } export type Letters = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z' export type SimpleNumbers = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 export type ArrayOneOrMore = { 0: T } & Array export type RecursiveObjValueType = { [K in keyof T]?: T[K] extends object ? Type | RecursiveObjValueType : Type; } export type TypeObjectValues, Type> = { [K in keyof Obj]: Type; } /** Return true | false whenever an object has a property of type U */ export type HasPropertyOfType, ExpectedType> = { [K in keyof Objectt]: Objectt[K] extends ExpectedType ? true : never; }[keyof Objectt] extends never ? false : true // https://stackoverflow.com/questions/49580725/is-it-possible-to-restrict-typescript-object-to-contain-only-properties-defined export type NoExtraProperties = U & MakeObjKeysAsNever> export type MakeObjKeysAsNever = { [P in K]: never } export type RemoveTypeFromTuple = T extends [] ? [] : T extends TypeToRemove ? [] : T extends [infer A, ...infer R] ? [ ...RemoveTypeFromTuple, ...RemoveTypeFromTuple ] : [T] export type GetTypeKeyFromObject = { [P in keyof ObjType]: ObjType[P] extends Type ? never : P; }[keyof ObjType] /** Remove object key/values that are of a certain type */ export type RemoveTypeFromObj = Pick< ObjType, GetTypeKeyFromObject > /** Get keys where the key type (number, string, Symbol...) is of Type */ export type GetObjectKeysThatAreOfType = { [P in keyof ObjType]: P extends Type ? P : never }[keyof ObjType] /** Remove Symbol and number from Object type */ export type ForceStringKeyObject> = Pick< Obj, GetObjectKeysThatAreOfType > /** Get all indices of an array as a type. Eg: 0 | 1 | 2... */ export type Indices = Exclude< Partial['length'], T['length'] > /** Remove Readonly Modifier */ export type Writeable = { -readonly [P in keyof T]: T[P] } /** Remove Readonly Modifier Recursively */ export type DeepWriteable = { -readonly [P in keyof T]: DeepWriteable } /** used to type generic function without having to do (...params: any) => any */ export type GenericFunction = (...params: any[]) => any /** used like IsObject extends true ? .... */ export type IsObject = T extends Record ? T extends GenericFunction ? false : T extends (any[] | readonly any[]) ? false : ConsiderDateAndRegexpsAsObjects extends false ? T extends (Date | RegExp) ? false : true : true : false export type ReadonlyDeep = { readonly [P in keyof T]: IsObject extends true ? ReadonlyDeep : T[P]; } /** Equivalent of { myPropA: string, otherProp?: never } | { myPropA?: never, otherProp: string }. This would be written Exclusive<{ myPropA: string }, { otherProp: string }> */ export type Exclusive< A extends Record, B extends Record, C extends Record = {}, D extends Record = {}, E extends Record = {} > = | ({ [P in Exclude]?: never; } & B) | ({ [P in Exclude]?: never; } & A) | ({ [P in Exclude]?: never; } & C) | ({ [P in Exclude]?: never; } & D) | ({ [P in Exclude]?: never; } & E) export type WeekDays = 0 | 1 | 2 | 3 | 4 | 5 | 6 export type StringAndUnion = T | (string & {}) export type ArrayKeys = keyof Arr & number export type PropsIntersection = (T extends any ? (x: T) => void : never) extends (x: infer R) => void ? R : never /** Giving a list of object, this will return a type similar to O1 & O2 & O3... * * It works well when with this structure ```type ObjOfObj = Record>``` * * Giving that structure, if you want to extract ```ObjOfObj[keyof ObjOfObj]``` the type may be never because its impossible to match O1 | O2... */ export type MergeMultipleObjects> = PropsIntersection /** Giving a list of required fields and subfields (dot notation) this type will return the object with the required fields added to type. @example ```ts export type Obj = { a: string; aOptional?: string; b: { c?: string d?: string e: string } } export type RequiredFields = { aOptional: true 'b.c': true } export type Result = AddRequiredFieldsToObject // PARSED TYPE: export type Obj = { a: string aOptional: string // this has became required because we specified it in RequiredFields b: { c: string // ALSO did this field d?: string // this one has kept being optional e: string // " " " " required } } ``` */ export type AddRequiredFieldsToObject, RequiredFields extends Record> = RemoveTypeFromObj extends true ? AddRequiredFieldsToObject : Obj[K] : never) : never : never }>, never> & RemoveTypeFromObj<{ [K in keyof Obj]: K extends string // ? Obj[K] extends any[] | readonly any[] ? Obj[K] : ? K extends keyof RequiredFields ? never : IsObject extends true ? AddRequiredFieldsToObject : Obj[K] : never }, never> /** * Removes the first element from a tuple type. * * @example * ```ts * type Example1 = RemoveFirst<[boolean, number, string]>; // [number, string] * type Example2 = RemoveFirst<[boolean, string]>; // [string] * type Example3 = RemoveFirst<[boolean]>; // [] * type Example4 = RemoveFirst<[]>; // never * ``` */ export type RemoveFirstElementFromTuple = T extends [any, ...infer Rest] ? Rest : never;