import { If, AllowsUndefined, AllowsNull } from "./TypeConditionals"; /** * Makes a target type `| undefined` if the source type is `| undefined`. * @example * type T = CopyUndefined; // string | undefined */ export type CopyUndefined = If< AllowsUndefined, TTarget | undefined, TTarget >; /** * Makes a target type `| null` if the source type is `| null`. * @example * type T = CopyNull; // string | undefined */ export type CopyNull = If< AllowsNull, TTarget | null, TTarget >; /** * Makes a target type `| null` and/or `| undefined` if the source * type is these. * @example * type T = CopyNullAndUndefined; // string | null | undefined */ export type CopyNullAndUndefined = If< AllowsNull, If, TTarget | null | undefined, TTarget | null>, If, TTarget | undefined, TTarget> >; /** * Removes `| undefined` from the type. * @example * type T = NotUndefined; // number */ export type NotUndefined = T extends undefined ? never : T; export type NotNull = T extends null ? never : T; /** * Makes all properties required to be present. Any that were previously optional are * allowed to be undefined. * @example * type T = Complete<{ * foo?: number; // becomes `foo: number | undefined` * }>; */ export type Complete = { [P in keyof Required]: Pick extends Required> ? T[P] : T[P] | undefined; }; /** * Makes the specified properties of T optional. * * @example * ```ts * // Both "id" and "name" becomes optional in the resulting type * Optional * `` */ export type Optional = Omit< T, K > & Partial>;