Home > @skunkteam/types > BaseTypeImpl > withConstraint
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>;
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>
Creates a brand. By creating a branded type, we ensure that TypeScript will consider this a separate type, see Branded for more information.