Skip to main content

Type Alias: RequiredIf<Value, ValueType, FallbackType>

RequiredIf<Value, ValueType, FallbackType>: If<Value, ValueType, ValueType | FallbackType>

A type utility that allows branching of an union type on the Value parameter.

Type Parameters

Type ParameterDefault type
Value extends boolean-
ValueType-
FallbackTypenull

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

Defined in

types.ts:283