# partial

> This document is the Markdown version of [valibot.dev/api/partial/](https://valibot.dev/api/partial/). 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.partial<TSchema, TKeys>(schema, keys);
```

## Generics

- `TSchema` `extends SchemaWithoutPipe<LooseObjectSchema<ObjectEntries, ErrorMessage<ObjectIssue> | undefined> | ObjectSchema<ObjectEntries, ErrorMessage<ObjectIssue> | undefined> | ObjectWithRestSchema<ObjectEntries, BaseSchema<unknown, unknown, BaseIssue<unknown>>, ErrorMessage<ObjectWithRestIssue> | undefined> | StrictObjectSchema<ObjectEntries, ErrorMessage<ObjectIssue> | undefined>>`
- `TKeys` `extends ObjectKeys<TSchema> | undefined`

## Parameters

- `schema` `TSchema`
- `keys` `TKey`

### Explanation

`partial` 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 `partial` changes the data type of the input and output, it is not allowed to pass a schema that has been modified by the [`pipe`](/api/pipe.md) method, as this may cause runtime errors. Please use the [`pipe`](/api/pipe.md) method after you have modified the schema with `partial`.

## Returns

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

## Examples

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

### Partial object schema

Schema to validate an object with partial entries.

```ts
const PartialSchema = v.partial(
  v.object({
    key1: v.string(),
    key2: v.number(),
  })
); // { key1?: string; key2?: number }
```

### With only specific keys

Schema to validate an object with only specific entries marked as optional.

```ts
const PartialSchema = v.partial(
  v.object({
    key1: v.string(),
    key2: v.number(),
    key3: v.boolean(),
  }),
  ['key1', 'key3']
); // { key1?: string; key2: number; key3?: boolean }
```

## Related

The following APIs can be combined with `partial`.

### 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), [`is`](/api/is.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`parse`](/api/parse.md), [`parser`](/api/parser.md), [`pick`](/api/pick.md), [`required`](/api/required.md), [`safeParse`](/api/safeParse.md), [`safeParser`](/api/safeParser.md), [`unwrap`](/api/unwrap.md)

### Actions

[`check`](/api/check.md), [`brand`](/api/brand.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)
