Skip to content

castConstraint

castConstraint extends the typing of an already constrained value by adding one or more compatible constraints. It does not re-validate the value; it only adds constraint markers. TypeScript prevents invalid casts.

Interactive example

Syntax

Classic signature

typescript
function castConstraint(
	constrainedType: ConstrainedType,
	constraintHandler: ConstraintHandler | ConstraintHandler[]
): ConstrainedType

Parameters

  • constrainedType: A value already carrying one or more constraints.
  • constraintHandler: A constraint handler (or an array of handlers) to add.

Return value

A new constrained value with the same wrapped value and the additional constraint markers.

See also

Released under the MIT license.