type Primitives = void | null | undefined | string | number | bigint | boolean | symbol; /** * Branded type that encodes possible thrown errors in the return type. * * Usage: * function fetchUser(id: string): Throws { ... } * * The actual runtime value is just T - the error types are phantom types * that exist only for static analysis. * * To indicate that a function shouldn't throw any errors, make it return `Throws`. */ export type Throws = | (T & { __throws?(error: E): void }) | Extract; /** * Extract the error types from a Throws type. */ export type ExtractErrors = T extends Throws ? E : never; /** * Extract the success type from a Throws type. */ export type ExtractSuccess = T extends Throws ? S : T; /** * Combine error types from multiple Throws types. */ export type CombineErrors = T extends [infer First, ...infer Rest] ? ExtractErrors | CombineErrors : never; /** * Helper to propagate errors - use this when your function calls other * throwing functions and wants to propagate their errors. */ export type PropagatesErrors = Throws< ExtractSuccess, ExtractErrors | AdditionalErrors >;