brand

Brands the output type of a schema.

const Schema = brand<TSchema, TName>(schema, name);

Generics

Parameters

  • schema TSchema
  • name TName

Explanation

brand allows you to brand the output type of schema with name. This ensures that data can only be considered valid if it has been validated by a particular branded schema.

Returns

Examples

The following examples show how brand can be used.

Branded fruit schema

Schema to ensure that only a validated fruit is accepted.

// Create schema and infer output type
const FruitSchema = brand(object({ name: string() }), 'Fruit');
type FruitOutput = Output<typeof FruitSchema>;

// This works because output is branded
const apple: FruitOutput = parse(FruitSchema, { name: 'apple' });

// But this will result in a type error
const banana: FruitOutput = { name: 'banana' };

The following APIs can be combined with brand.

Schemas

Methods

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of fabian-hiller

Partners

Thanks to our partners who support the project ideally and financially.

Sponsors

Thanks to our GitHub sponsors who support the project financially.

  • GitHub profile picture of dailydotdev
  • GitHub profile picture of ivan-mihalic
  • GitHub profile picture of KATT
  • GitHub profile picture of osdiab
  • GitHub profile picture of Thanaen
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of caegdeveloper