/** * Conditional utility types for TypeScript * @module ConditionalTypes */ /** * Checks if T is exactly U * @template T - The type to check * @template U - The type to compare against * @example * ```typescript * type IsString = Is; // true * type IsNumber = Is; // false * ``` */ export type Is = T extends U ? U extends T ? true : false : false; /** * Checks if T is assignable to U * @template T - The type to check * @template U - The target type * @example * ```typescript * type CanAssign = Extends; // true * type CannotAssign = Extends; // false * ``` */ export type Extends = T extends U ? true : false; /** * Returns T if condition is true, otherwise U * @template Condition - The boolean condition * @template T - The type to return if true * @template U - The type to return if false * @example * ```typescript * type Result = If; // string * type Result2 = If; // number * ``` */ export type If = Condition extends true ? T : U; /** * Returns T if T is not never, otherwise U * @template T - The primary type * @template U - The fallback type * @example * ```typescript * type Result = NotNever; // string * type Result2 = NotNever; // number * ``` */ export type NotNever = T extends never ? U : T; /** * Returns T if T is not null, otherwise U * @template T - The primary type * @template U - The fallback type * @example * ```typescript * type Result = NotNull; // string * type Result2 = NotNull; // number * ``` */ export type NotNull = T extends null ? U : T; /** * Returns T if T is not undefined, otherwise U * @template T - The primary type * @template U - The fallback type * @example * ```typescript * type Result = NotUndefined; // string * type Result2 = NotUndefined; // number * ``` */ export type NotUndefined = T extends undefined ? U : T; /** * Returns T if T is not null or undefined, otherwise U * @template T - The primary type * @template U - The fallback type * @example * ```typescript * type Result = NotNullOrUndefined; // string * type Result2 = NotNullOrUndefined; // number * type Result3 = NotNullOrUndefined; // number * ``` */ export type NotNullOrUndefined = T extends null | undefined ? U : T; /** * Returns true if T is a union type, false otherwise * @template T - The type to check * @example * ```typescript * type IsUnion = IsUnion; // true * type IsNotUnion = IsUnion; // false * ``` */ export type IsUnion = T extends any ? [any] extends [T] ? false : true : false; /** * Returns true if T is an array type, false otherwise * @template T - The type to check * @example * ```typescript * type IsArray = IsArray; // true * type IsNotArray = IsArray; // false * ``` */ export type IsArray = T extends readonly any[] ? true : false; /** * Returns true if T is a tuple type, false otherwise * @template T - The type to check * @example * ```typescript * type IsTuple = IsTuple<[string, number]>; // true * type IsNotTuple = IsTuple; // false * ``` */ export type IsTuple = T extends readonly any[] ? number extends T['length'] ? false : true : false; /** * Returns true if T is a function type, false otherwise * @template T - The type to check * @example * ```typescript * type IsFunction = IsFunction<() => void>; // true * type IsNotFunction = IsFunction; // false * ``` */ export type IsFunction = T extends (...args: any) => any ? true : false; /** * Returns true if T is a primitive type, false otherwise * @template T - The type to check * @example * ```typescript * type IsPrimitive = IsPrimitive; // true * type IsNotPrimitive = IsPrimitive; // false * ``` */ export type IsPrimitive = T extends string | number | boolean | symbol | null | undefined ? true : false; //# sourceMappingURL=conditional.d.ts.map