---
title: partial
description: >-
  Creates a modified copy of an object schema that marks all or only the
  selected entries as optional.
source: /methods/partial/partial.ts
contributors:
  - fabian-hiller
---

import { ApiList, Link, Property } from '~/components';
import { properties } from './properties';

# partial

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` <Property {...properties.TSchema} />
- `TKeys` <Property {...properties.TKeys} />

## Parameters

- `schema` <Property {...properties.schema} />
- `keys` <Property {...properties.keys} />

### 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 <Link href='../pipe/'>`pipe`</Link> method, as this may cause runtime errors. Please use the <Link href='../pipe/'>`pipe`</Link> method after you have modified the schema with `partial`.

## Returns

- `Schema` <Property {...properties.Schema} />

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

<ApiList
  items={[
    'array',
    'exactOptional',
    'intersect',
    'lazy',
    'looseObject',
    'looseTuple',
    'map',
    'nonNullable',
    'nonNullish',
    'nonOptional',
    'nullable',
    'nullish',
    'object',
    'objectWithRest',
    'optional',
    'record',
    'set',
    'strictObject',
    'strictTuple',
    'tuple',
    'tupleWithRest',
    'undefinedable',
    'union',
  ]}
/>

### Methods

<ApiList
  items={[
    'assert',
    'config',
    'fallback',
    'forward',
    'getDefault',
    'getDefaults',
    'getFallback',
    'getFallbacks',
    'is',
    'keyof',
    'message',
    'omit',
    'parse',
    'parser',
    'pick',
    'required',
    'safeParse',
    'safeParser',
    'unwrap',
  ]}
/>

### Actions

<ApiList
  items={[
    'check',
    'brand',
    'description',
    'entries',
    'flavor',
    'guard',
    'maxEntries',
    'metadata',
    'minEntries',
    'notEntries',
    'partialCheck',
    'rawCheck',
    'rawTransform',
    'readonly',
    'title',
    'transform',
  ]}
/>

### Utils

<ApiList items={['isOfKind', 'isOfType']} />
