Spec-Zone.ru › Valibot

returns

Creates a function return transformation action.

const Action = v.returns<TInput, TSchema>(schema);

Generics

  • TInput extends (...args: any[]) => unknown
  • TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>

Parameters

  • schema TSchema

Explanation

With returns you can force the returned value of a function to match the given schema.

Returns

  • Action ReturnsAction<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

pipe

Utils

isOfKind, isOfType

© Fabian Hiller
Licensed under the MIT License.
https://valibot.dev/api/returns/

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API