brand

Creates a brand transformation action.

const Action = v.brand<TInput, TName>(name);

Generics

Parameters

  • name TName

Explanation

brand allows you to brand the output type of a schema with a 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 = v.pipe(v.object({ name: v.string() }), v.brand('Fruit'));
type FruitOutput = v.InferOutput<typeof FruitSchema>;

// This works because output is branded
const apple: FruitOutput = v.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

Utils

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 antfu
  • GitHub profile picture of Thanaen
  • GitHub profile picture of osdiab
  • GitHub profile picture of ruiaraujo012
  • GitHub profile picture of hyunbinseo
  • GitHub profile picture of F0rce
  • GitHub profile picture of Unique-Pixels
  • GitHub profile picture of jdgamble555
  • GitHub profile picture of nickytonline
  • GitHub profile picture of KubaJastrz
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of dslatkin