# partialAsync

> This document is the Markdown version of [valibot.dev/api/partialAsync/](https://valibot.dev/api/partialAsync/). For the complete documentation index, see [llms.txt](https://valibot.dev/llms.txt).

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

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

## Generics

- `TSchema` `extends SchemaWithoutPipe<LooseObjectSchemaAsync<ObjectEntriesAsync, ErrorMessage<LooseObjectIssue> | undefined> | ObjectSchemaAsync<ObjectEntriesAsync, ErrorMessage<ObjectIssue> | undefined> | ObjectWithRestSchemaAsync<ObjectEntriesAsync, BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, ErrorMessage<ObjectWithRestIssue> | undefined> | StrictObjectSchemaAsync<ObjectEntriesAsync, ErrorMessage<StrictObjectIssue> | undefined>>`
- `TKeys` `extends ObjectKeys<TSchema> | undefined`

## 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`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) 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`](/api/pipeAsync.md) method, as this may cause runtime errors. Please use the [`pipeAsync`](/api/pipeAsync.md) method after you have modified the schema with `partialAsync`.

## Returns

- `Schema` `SchemaWithPartialAsync<TSchema, TKeys>`

## Examples

The following examples show how `partialAsync` can be used.

### Update user schema

Schema to update the user details.

```ts
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;
  }
*/
```

## Related

The following APIs can be combined with `partialAsync`.

### Schemas

[`array`](/api/array.md), [`exactOptional`](/api/exactOptional.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md)

### Methods

[`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`forward`](/api/forward.md), [`getDefault`](/api/getDefault.md), [`getDefaults`](/api/getDefaults.md), [`getFallback`](/api/getFallback.md), [`getFallbacks`](/api/getFallbacks.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`pick`](/api/pick.md), [`required`](/api/required.md), [`unwrap`](/api/unwrap.md)

### Actions

[`brand`](/api/brand.md), [`check`](/api/check.md), [`description`](/api/description.md), [`entries`](/api/entries.md), [`flavor`](/api/flavor.md), [`guard`](/api/guard.md), [`maxEntries`](/api/maxEntries.md), [`metadata`](/api/metadata.md), [`minEntries`](/api/minEntries.md), [`notEntries`](/api/notEntries.md), [`partialCheck`](/api/partialCheck.md), [`rawCheck`](/api/rawCheck.md), [`rawTransform`](/api/rawTransform.md), [`readonly`](/api/readonly.md), [`title`](/api/title.md), [`transform`](/api/transform.md)

### Utils

[`isOfKind`](/api/isOfKind.md), [`isOfType`](/api/isOfType.md)

### Async

[`arrayAsync`](/api/arrayAsync.md), [`checkAsync`](/api/checkAsync.md), [`exactOptionalAsync`](/api/exactOptionalAsync.md), [`fallbackAsync`](/api/fallbackAsync.md), [`forwardAsync`](/api/forwardAsync.md), [`getDefaultsAsync`](/api/getDefaultsAsync.md), [`getFallbacksAsync`](/api/getFallbacksAsync.md), [`intersectAsync`](/api/intersectAsync.md), [`lazyAsync`](/api/lazyAsync.md), [`looseObjectAsync`](/api/looseObjectAsync.md), [`looseTupleAsync`](/api/looseTupleAsync.md), [`mapAsync`](/api/mapAsync.md), [`nonNullableAsync`](/api/nonNullableAsync.md), [`nonNullishAsync`](/api/nonNullishAsync.md), [`nonOptionalAsync`](/api/nonOptionalAsync.md), [`nullableAsync`](/api/nullableAsync.md), [`nullishAsync`](/api/nullishAsync.md), [`objectAsync`](/api/objectAsync.md), [`objectWithRestAsync`](/api/objectWithRestAsync.md), [`optionalAsync`](/api/optionalAsync.md), [`parseAsync`](/api/parseAsync.md), [`parserAsync`](/api/parserAsync.md), [`partialCheckAsync`](/api/partialCheckAsync.md), [`rawCheckAsync`](/api/rawCheckAsync.md), [`rawTransformAsync`](/api/rawTransformAsync.md), [`recordAsync`](/api/recordAsync.md), [`requiredAsync`](/api/requiredAsync.md), [`safeParseAsync`](/api/safeParseAsync.md), [`safeParserAsync`](/api/safeParserAsync.md), [`setAsync`](/api/setAsync.md), [`strictObjectAsync`](/api/strictObjectAsync.md), [`strictTupleAsync`](/api/strictTupleAsync.md), [`transformAsync`](/api/transformAsync.md), [`tupleAsync`](/api/tupleAsync.md), [`tupleWithRestAsync`](/api/tupleWithRestAsync.md), [`undefinedableAsync`](/api/undefinedableAsync.md), [`unionAsync`](/api/unionAsync.md)
