returns
Creates a function return transformation action.
const Action = v.returns<TInput, TSchema>(schema);
Generics
TInputextends (...args: any[]) => unknownTSchemaextends BaseSchema<unknown, unknown, BaseIssue<unknown>>
Parameters
schemaTSchema
Explanation
With returns you can force the returned value of a function to match the given schema.
Returns
ActionReturnsAction<TInput, TSchema>
Examples
The following examples show how returns can be used.
Function schema
Schema of a function that transforms a string to a number.
const FunctionSchema = v.pipe(
v.function(),
v.args(v.tuple([v.pipe(v.string(), v.decimal())])),
v.returns(v.number())
);
Related
The following APIs can be combined with returns.
Schemas
any, array, bigint, blob, boolean, custom, date, enum, exactOptional, file, function, instance, intersect, lazy, literal, looseObject, looseTuple, map, nan, never, nonNullable, nonNullish, nonOptional, null, nullable, nullish, number, object, objectWithRest, optional, picklist, promise, record, set, strictObject, strictTuple, string, symbol, tuple, tupleWithRest, undefined, undefinedable, union, unknown, variant, void
Methods
Utils
© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/returns/