objectWithRestAsync

Creates an object with rest schema.

const Schema = v.objectWithRestAsync<TEntries, TRest, TMessage>(
  entries,
  rest,
  message
);

Generics

Parameters

  • entries TEntries
  • rest TRest
  • message TMessage

Explanation

With objectWithRestAsync you can validate the data type of the input and whether the content matches entries and rest. If the input is not an object, you can use message to customize the error message.

The difference to objectAsync is that this schema includes unknown entries in the output. In addition, this schema filters certain entries from the unknown entries for security reasons.

This schema does not distinguish between missing and undefined entries. The reason for this decision is that it reduces the bundle size, and we also expect that most users will expect this behavior.

Returns

Examples

The following examples show how objectWithRestAsync can be used. Please see the object guide for more examples and explanations.

Word map schema

Schema to validate an object with word map mutation details.

import { isUserAllowedToMutate } from '~/api';

// Assume the rest of the keys are always English words
const WordMapSchema = v.objectWithRestAsync(
  {
    $userId: v.pipeAsync(
      v.string(),
      v.regex(/^[a-z0-9]{12}$/i),
      v.checkAsync(
        isUserAllowedToMutate,
        'The user is not allowed to change the word map.'
      )
    ),
    $targetLanguage: v.union([
      v.literal('hindi'),
      v.literal('spanish'),
      v.literal('french'),
    ]),
  },
  v.string()
);

The following APIs can be combined with objectWithRestAsync.

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 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 dslatkin