export type NonNullableObject = { [P in keyof T]-?: NonNullable; }; /** Shorthand alias */ export type AnyFunc = (...args: any[]) => any; /** A tuple without its last element */ export type OmitLast = T extends [...infer REST, any] ? REST : never; /** F with all arguments but the last */ export type OmitLastParam = (...args: OmitLast>) => ReturnType; export type OmitFirst = T extends [any, ...infer REST] ? REST : never; export type OmitFirstParam = T extends (...args: any[]) => any ? (...args: OmitFirst>) => ReturnType : never; /** Require that T has at least one of the provided properties defined */ export type RequireAtLeastOne = Pick> & { [K in Keys]-?: Required> & Partial>>; }[Keys]; /** Verify that an type _Copy extends _Orig */ export declare function checkExtends<_Orig, _Copy extends _Orig>(): void; export type Replace = Omit & New; /** An object T with any nested values of type ToReplace replaced with ReplaceWith */ export type ReplaceNested = T extends (...args: any[]) => any ? T : [keyof T] extends [never] ? T : T extends Record ? T : T extends { [k: string]: ToReplace; } ? { [P in keyof T]: ReplaceNested; } : T extends ToReplace ? ReplaceWith | Exclude : { [P in keyof T]: ReplaceNested; }; export type UnionToIntersection = (Union extends unknown ? (distributedUnion: Union) => void : never) extends (mergedIntersection: infer Intersection) => void ? // The `& Union` is to allow indexing by the resulting type Intersection & Union : never; type IsEqual = (() => G extends A ? 1 : 2) extends () => G extends B ? 1 : 2 ? true : false; type Primitive = null | undefined | string | number | boolean | symbol | bigint; type IsNull = [T] extends [null] ? true : false; type IsUnknown = unknown extends T ? IsNull extends false ? true : false : false; type ObjectValue = K extends keyof T ? T[K] : ToString extends keyof T ? T[ToString] : K extends `${infer NumberK extends number}` ? NumberK extends keyof T ? T[NumberK] : never : never; type ToString = T extends string | number ? `${T}` : never; type KeysOfUnion = ObjectType extends unknown ? keyof ObjectType : never; type ArrayElement = T extends readonly unknown[] ? T[0] : never; type ExactObject = { [Key in keyof ParameterType]: Exact>; } & Record>, never>; export type Exact = IsEqual extends true ? ParameterType : ParameterType extends Primitive ? ParameterType : IsUnknown extends true ? unknown : ParameterType extends Function ? ParameterType : ParameterType extends unknown[] ? Array, ArrayElement>> : ParameterType extends readonly unknown[] ? ReadonlyArray, ArrayElement>> : ExactObject; export type RemovePrefix = { [k in Keys]: k extends `${Prefix}${infer Suffix}` ? Suffix : never; }[Keys]; export declare function isRecord(value: unknown): value is Record; export declare function hasOwnProperty, Y extends PropertyKey>(record: X, prop: Y): record is X & Record; export declare function hasOwnProperties, Y extends PropertyKey>(record: X, props: Y[]): record is X & Record; export declare function isError(error: unknown): error is Error; export declare function isAbortError(error: unknown): error is Error & { name: 'AbortError'; }; /** * Get `error.message` (or `undefined` if not present) */ export declare function errorMessage(error: unknown): string | undefined; /** * Get `error.code` (or `undefined` if not present) */ export declare function errorCode(error: unknown): string | undefined; /** * Asserts that some type is the never type */ export declare function assertNever(msg: string, x: never): never; export type Class = { new (...args: any[]): E; prototype: E; }; /** * A decorator to be used on error classes. It adds the 'name' property AND provides a custom * 'instanceof' handler that works correctly across execution contexts. * * ### Details ### * * According to the EcmaScript's spec, the default behavior of JavaScript's `x instanceof Y` operator is to walk up the * prototype chain of object 'x', checking if any constructor in that hierarchy is _exactly the same object_ as the * constructor function 'Y'. * * Unfortunately, it happens in various situations that different constructor function objects get created for what * appears to be the very same class. This leads to surprising behavior where `instanceof` returns false though it is * known that the object is indeed an instance of that class. One particular case where this happens is when constructor * 'Y' belongs to a different realm than the constuctor with which 'x' was instantiated. Another case is when two copies * of the same library gets loaded in the same realm. * * In practice, this tends to cause issues when crossing the workflow-sandboxing boundary (since Node's vm module * really creates new execution realms), as well as when running tests using Jest (see https://github.com/jestjs/jest/issues/2549 * for some details on that one). * * This function injects a custom 'instanceof' handler into the prototype of 'clazz', which is both cross-realm safe and * cross-copies-of-the-same-lib safe. It works by adding a special symbol property to the prototype of 'clazz', and then * checking for the presence of that symbol. */ export declare function SymbolBasedInstanceOfError(markerName: string): (clazz: Class) => void; export {};