partialAsync

Creates a modified copy of an object schema that marks all or only the selected entries as optional.

const Schema = v.partialAsync<TSchema, TKeys>(schema, keys);

Generics

Parameters

  • schema TSchema
  • keys TKey

Explanation

partialAsync creates a modified copy of the given object schema where all entries or only the selected keys are optional. It is similar to TypeScript's Partial utility type.

Because partialAsync changes the data type of the input and output, it is not allowed to pass a schema that has been modified by the pipeAsync method, as this may cause runtime errors. Please use the pipeAsync method after you have modified the schema with partialAsync.

Returns

Examples

The following examples show how partialAsync can be used.

Update user schema

Schema to update the user details.

import { isEmailAbsent, isUsernameAbsent } from '~/api';

const UserSchema = v.objectAsync({
  email: v.pipeAsync(
    v.string(),
    v.email(),
    v.checkAsync(isEmailAbsent, 'The email is already in the database.')
  ),
  username: v.pipeAsync(
    v.string(),
    v.nonEmpty(),
    v.checkAsync(isUsernameAbsent, 'The username is already in the database.')
  ),
  password: v.pipe(v.string(), v.minLength(8)),
});

const UpdateUserSchema = v.partialAsync(UserSchema);

/*
  { 
    email?: string;
    username?: string; 
    password?: string;
  }
*/

The following APIs can be combined with partialAsync.

Schemas

Methods

Actions

Utils

Async

Contributors

Thanks to all the contributors who helped make this page better!

  • GitHub profile picture of fabian-hiller
  • GitHub profile picture of EltonLobo07

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 fabulousgk
  • GitHub profile picture of jdgamble555
  • GitHub profile picture of nickytonline
  • GitHub profile picture of KubaJastrz
  • GitHub profile picture of caegdeveloper
  • GitHub profile picture of luckasnix
  • GitHub profile picture of andrew-3kb
  • GitHub profile picture of dslatkin