returnsAsync

Creates a function return transformation action.

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

Generics

Parameters

  • schema TSchema

Explanation

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

Returns

Examples

The following examples show how returnsAsync can be used.

Product function schema

Schema of a function that returns a product by its ID.

import { isValidProductId } from '~/api';

const ProductFunctionSchema = v.pipeAsync(
  v.function(),
  v.argsAsync(
    v.tupleAsync([v.pipeAsync(v.string(), v.checkAsync(isValidProductId))])
  ),
  v.returnsAsync(
    v.pipeAsync(
      v.promise(),
      v.awaitAsync(),
      v.object({
        id: v.string(),
        name: v.string(),
        price: v.number(),
      })
    )
  )
);

The following APIs can be combined with returnsAsync.

Schemas

Methods

Utils

Async

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 akhmadqasim
  • GitHub profile picture of dslatkin