-
Notifications
You must be signed in to change notification settings - Fork 0
constraint
runtypes / Exports / Constraint
Name | Type | Default |
---|---|---|
A |
Runtype | - |
T |
Static<A> | Static<A> |
K |
- | unknown |
-
Runtype<T>
↳ Constraint
• constructor: object
Inherited from: void
• Readonly
_falseWitness: T
Inherited from: Runtype._falseWitness
Defined in: src/runtype.ts:39
• Optional
args: K
Defined in: src/types/constraint.ts:16
• Optional
name: string
Defined in: src/types/constraint.ts:15
• Readonly
reflect: Reflect
Convert this to a Reflect, capable of introspecting the structure of the type.
Inherited from: Runtype.reflect
Defined in: src/runtype.ts:37
• tag: constraint
Defined in: src/types/constraint.ts:10
• underlying: A
Defined in: src/types/constraint.ts:11
▸ And<B>(B
: B): Intersect<[Constraint<A, T, K>, B]>
Intersect this Runtype with another.
Name | Type |
---|---|
B |
Runtype<unknown, B> |
Name | Type |
---|---|
B |
B |
Returns: Intersect<[Constraint<A, T, K>, B]>
Inherited from: Runtype
Defined in: src/runtype.ts:54
▸ Or<B>(B
: B): Union<[Constraint<A, T, K>, B]>
Union this Runtype with another.
Name | Type |
---|---|
B |
Runtype<unknown, B> |
Name | Type |
---|---|
B |
B |
Returns: Union<[Constraint<A, T, K>, B]>
Inherited from: Runtype
Defined in: src/runtype.ts:49
▸ assert(x
: any): asserts x is T
Verifies that a value conforms to this runtype. When given a value that does not conform to the runtype, throws an exception.
Name | Type |
---|---|
x |
any |
Returns: asserts x is T
Inherited from: Runtype
Defined in: src/runtype.ts:15
▸ check(x
: any): T
Verifies that a value conforms to this runtype. If so, returns the same value, statically typed. Otherwise throws an exception.
Name | Type |
---|---|
x |
any |
Returns: T
Inherited from: Runtype
Defined in: src/runtype.ts:21
▸ constraint(x
: Static<A>): string | boolean
Name | Type |
---|---|
x |
Static<A> |
Returns: string | boolean
Defined in: src/types/constraint.ts:14
▸ guard(x
: any): x is T
A type guard for this runtype.
Name | Type |
---|---|
x |
any |
Returns: x is T
Inherited from: Runtype
Defined in: src/runtype.ts:32
▸ optional(): Optional<Constraint<A, T, K>>
Optionalize this Runtype.
Returns: Optional<Constraint<A, T, K>>
Inherited from: Runtype
Defined in: src/runtype.ts:59
▸ validate(x
: any): Result<T>
Validates that a value conforms to this type, and returns a result indicating success or failure (does not throw).
Name | Type |
---|---|
x |
any |
Returns: Result<T>
Inherited from: Runtype
Defined in: src/runtype.ts:27
▸ withBrand<B>(brand
: B): Brand<B, Constraint<A, T, K>>
Adds a brand to the type.
Name | Type |
---|---|
B |
string |
Name | Type |
---|---|
brand |
B |
Returns: Brand<B, Constraint<A, T, K>>
Inherited from: Runtype
Defined in: src/runtype.ts:102
▸ withConstraint<T, K>(constraint
: ConstraintCheck<Constraint<A, T, K>>, options?
: { args?
: K ; name?
: string }): Constraint<Constraint<A, T, K>, T, K>
Use an arbitrary constraint function to validate a runtype, and optionally to change its name and/or its static type.
Name | Type | Default | Description |
---|---|---|---|
T |
unknown | - | Optionally override the static type of the resulting runtype |
K |
- | unknown | - |
Name | Type | Description |
---|---|---|
constraint |
ConstraintCheck<Constraint<A, T, K>> | Custom function that returns true if the constraint is satisfied, false or a custom error message if not. |
options? |
object | - |
options.args? |
K | - |
options.name? |
string | - |
Returns: Constraint<Constraint<A, T, K>, T, K>
Inherited from: Runtype
Defined in: src/runtype.ts:74
▸ withGuard<T, K>(guard
: (x
: T) => x is T, options?
: { args?
: K ; name?
: string }): Constraint<Constraint<A, T, K>, T, K>
Helper function to convert an underlying Runtype into another static type via a type guard function. The static type of the runtype is inferred from the type of the guard function.
Name | Type | Default | Description |
---|---|---|---|
T |
unknown | - | Typically inferred from the return type of the type guard function, so usually not needed to specify manually. |
K |
- | unknown | - |
Name | Type | Description |
---|---|---|
guard |
(x : T) => x is T |
Type guard function (see https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards) |
options? |
object | - |
options.args? |
K | - |
options.name? |
string | - |
Returns: Constraint<Constraint<A, T, K>, T, K>
Inherited from: Runtype
Defined in: src/runtype.ts:94