Skip to content

Latest commit

 

History

History
28 lines (17 loc) · 1.4 KB

types.basetypeimpl.withconstraint.md

File metadata and controls

28 lines (17 loc) · 1.4 KB

Home > @skunkteam/types > BaseTypeImpl > withConstraint

BaseTypeImpl.withConstraint() method

Create a new type based on the current type and use the given constraint function as validation.

Signature:

withConstraint<const BrandName extends string>(name: BrandName, constraint: Validator<ResultType>): Type<Branded<ResultType, BrandName>, TypeConfig>;

Parameters

Parameter Type Description
name BrandName the new name to use in error messages
constraint Validator<ResultType> the additional validation to restrict the current type

Returns:

Type<Branded<ResultType, BrandName>, TypeConfig>

Remarks

Creates a brand. By creating a branded type, we ensure that TypeScript will consider this a separate type, see Branded for more information.