Type Alias: If<Value, TrueResult, FalseResult>
If<
Value
,TrueResult
,FalseResult
>:Value
extendstrue
?TrueResult
:Value
extendsfalse
?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[]