/** * Makes specified properties of a type optional while keeping others required. * * @template T - The original type * @template K - Keys of T to make optional * * @example * type User = { name: string; age: number; email: string; } * type UserWithOptionalEmail = WithOptional; * // Result: { name: string; age: number; email?: string; } */ export type WithOptional = Omit & Partial>; /** * Makes specified properties of a type required by removing optional modifiers. * * @template T - The original type * @template K - Keys of T to make required * * @example * type User = { name?: string; age?: number; } * type RequiredUser = WithRequired; * // Result: { name: string; age?: number; } */ export type WithRequired = T & { [P in K]-?: T[P]; }; /** * Represents a value that can be either the value itself or a Promise of that value. * Used for functions that can return either synchronously or asynchronously. * * @template T - The type of the value * * @example * type Result = SelfOrPromise; * // Can be: number | Promise */ export type SelfOrPromise = T | Promise; /** * Represents a value that can be either a single item or an array of items. * Useful for parameters that accept either one or multiple values. * * @template T - The type of the item(s) * * @example * type IdParam = OneOrMany; * // Can be: string | string[] */ export type OneOrMany = T | Array; /** * The variant a discriminated union publishes for a value the client does not know, because the API * gained it after the client shipped. * * @template Discriminant - The key the union discriminates on, `type` for most of them * * @example * type Target = TargetEmail | TargetUser | UnknownToClient; * // A target the client cannot map: { type: 'UNKNOWN_TO_CLIENT', payload: } * * @example * type Event = ClusterStatusEvent | NodeLifecycleEvent | UnknownToClient<'event'>; * // An event the client cannot map: { event: 'UNKNOWN_TO_CLIENT', payload: } */ export type UnknownToClient = { [K in Discriminant]: 'UNKNOWN_TO_CLIENT'; } & { /** The payload as the API sent it, so a caller can still read what the client could not map. */ payload: unknown; }; /** * The members of a discriminated union the client does know, with {@link UnknownToClient} taken out. * * A union that carries the unknown variant forces every caller to handle it, which is the point. A * caller that has already dealt with it, or that filters it out of a list, names the rest with this. * * @template T - The discriminated union to narrow * @template Discriminant - The key the union discriminates on, `type` for most of them * * @example * type Target = TargetEmail | TargetUser | UnknownToClient; * type KnownTarget = Known; * // Result: TargetEmail | TargetUser * * @example * type Event = ClusterStatusEvent | NodeLifecycleEvent | UnknownToClient<'event'>; * type KnownEvent = Known; * // Result: ClusterStatusEvent | NodeLifecycleEvent */ export type Known = Exclude>; //# sourceMappingURL=utils.types.d.ts.map