Skip to main content

Type Alias: If<Value, TrueResult, FalseResult>

If<Value, TrueResult, FalseResult>: Value extends true ? TrueResult : Value extends false ? FalseResult : TrueResult | FalseResult

A type utility that allows branching of types depending on the Value parameter.

Type Parameters

Type Parameter
Value extends boolean
TrueResult
FalseResult

Example

declare function get<const GetValues extends boolean = false>(
getValues?: GetValues
): If<GetValues, string, string[]>;

const a = get(true);
// ^? string

const b = get(false);
// ^? string[]

declare const someBoolean: boolean;
const c = get(someBoolean);
// ^? string | string[]

Defined in

types.ts:258