# flavor

> This document is the Markdown version of [valibot.dev/api/flavor/](https://valibot.dev/api/flavor/). For the complete documentation index, see [llms.txt](https://valibot.dev/llms.txt).

Creates a flavor transformation action.

```ts
const Action = v.flavor<TInput, TName>(name);
```

## Generics

- `TInput` `extends any`
- `TName` `extends FlavorName`

## Parameters

- `name` `TName`

### Explanation

`flavor` is a less strict version of [`brand`](/api/brand.md) that allows you to flavor the output type of a schema with a `name`. Data is considered valid if it's type is unflavored or has been validated by a schema that has the same flavor.

> `flavor` can also be used as a TypeScript DX hack to improve the editor's autocompletion by displaying only literal types, but still allowing the unflavored root type to be passed.

## Returns

- `Action` `FlavorAction<TInput, TName>`

## Examples

The following examples show how `flavor` can be used.

### Flavored ID schemas

Schema to ensure that different types of IDs are not mixed up.

```ts
// Create user ID and order ID schema
const UserIdSchema = v.pipe(v.string(), v.flavor('UserId'));
const OrderIdSchema = v.pipe(v.string(), v.flavor('OrderId'));

// Infer output types of both schemas
type UserId = v.InferOutput<typeof UserIdSchema>;
type OrderId = v.InferOutput<typeof OrderIdSchema>;

// This works because output is flavored
const userId: UserId = v.parse(UserIdSchema, 'c28443ef...');
const orderId: OrderId = v.parse(OrderIdSchema, '4b717520...');

// You can also use unflavored strings
const newUserId1: UserId = '2d80cd94...';

// But this will result in a type error
const newUserId2: UserId = orderId;
```

## Related

The following APIs can be combined with `flavor`.

### Schemas

[`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md)

### Methods

[`pipe`](/api/pipe.md)

### Utils

[`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md)
