Type Alias: RequiredIf<Value, ValueType, FallbackType>
RequiredIf<
Value,ValueType,FallbackType> =If<Value,ValueType,ValueType|FallbackType>
Defined in: types.ts:283
A type utility that allows branching of an union type on the Value parameter.
Type Parameters
| Type Parameter | Default type |
|---|---|
Value extends boolean | - |
ValueType | - |
FallbackType | null |
Example
declare function get<const Required extends boolean = false>(
required?: Required
): If<Required, string>;
const a = get(true);
// ^? string
const b = get(false);
// ^? string | null
declare const someBoolean: boolean;
const c = get(someBoolean);
// ^? string | null