Options
These are typical options available to the types and what do they mean.
π Predicate
Section titled βπ Predicateβπ :performing_arts:
Predicate is also known as validate or logical.
When the input satisfies the predicate, the type returns true. Otherwise, false.
It is one of the $Selection options (selection: 'predicate').
Typically, it is the default option.
(other icons considered: β)
πͺοΈ Filter
Section titled βπͺοΈ FilterβπͺοΈ :tornados:
Filter is a type or function that filters the input.
If the input passes the filter, it is returned unchanged. Otherwise, it returns never.
Filter is also known as pares, as in Parse, donβt validate.
It is one of the $Selection options (selection: 'filter').
The returned input can be narrowed if π distributive is also enabled. This means it is better to infer the return type instead of reusing the input type:
type IsUndefined<T> = T extends undefined ? T : never
// yes, these are silly, but just an exampletype Bad<T> = IsUndefined<T> extends T ? T : nevertype Good<T> = IsUndefined<T> extends infer R ? R : never
type R1 = Bad<undefined | number> // undefined | numbertype R2 = Good<undefined | number> // undefined(other icons considered: βͺοΈππβ©πΎππͺππ§²π ββοΈπͺ)
π Distributive
Section titled βπ Distributiveβπ :twisted_rightwards_arrows:
Distributive means each value in a union type will be evaluated separately in conditional types, so both branches may be executed.
type R = IsUndefined<string | undefined> // true | false -> booleanTypically, most types are distributive by default.
π Exact
Section titled βπ Exactβπ :pushpin:
Exact means type comparison will be performed strictly, treating subtype as separate types.
type R1 = IsString<'a', { exact: true }> // falseπ± Branching
Section titled βπ± Branchingβπ± :trident:
Branching allows you to control the behavior of the types with type branching.
type R = IsNever<Input, { $any: 1, $unknown: 2, $then: 3, $else: 4,}>