# getDefaults

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

Returns the default values of the schema.

> The difference to [`getDefault`](/api/getDefault.md) is that for object and tuple schemas this function recursively returns the default values of the subschemas instead of `undefined`.

```ts
const values = v.getDefaults<TSchema>(schema);
```

## Generics

- `TSchema` `extends BaseSchema<unknown, unknown, BaseIssue<unknown>>`

## Parameters

- `schema` `TSchema`

## Returns

- `values` `InferDefaults<TSchema>`

## Examples

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

### Object defaults

Get the default values of an object schema.

```ts
const ObjectSchema = v.object({
  key: v.optional(v.string(), "I'm the default!"),
});

const defaultValues = v.getDefaults(ObjectSchema); // { key: "I'm the default!" }
```

### Tuple defaults

Get the default values of a tuple schema.

```ts
const TupleSchema = v.tuple([v.nullable(v.number(), 100)]);
const defaultValues = v.getDefaults(TupleSchema); // [100]
```

## Related

The following APIs can be combined with `getDefaults`.

### Schemas

[`any`](/api/any.md), [`array`](/api/array.md), [`bigint`](/api/bigint.md), [`blob`](/api/blob.md), [`boolean`](/api/boolean.md), [`custom`](/api/custom.md), [`date`](/api/date.md), [`enum`](/api/enum.md), [`exactOptional`](/api/exactOptional.md), [`file`](/api/file.md), [`function`](/api/function.md), [`instance`](/api/instance.md), [`intersect`](/api/intersect.md), [`lazy`](/api/lazy.md), [`literal`](/api/literal.md), [`looseObject`](/api/looseObject.md), [`looseTuple`](/api/looseTuple.md), [`map`](/api/map.md), [`nan`](/api/nan.md), [`never`](/api/never.md), [`nonNullable`](/api/nonNullable.md), [`nonNullish`](/api/nonNullish.md), [`nonOptional`](/api/nonOptional.md), [`null`](/api/null.md), [`nullable`](/api/nullable.md), [`nullish`](/api/nullish.md), [`number`](/api/number.md), [`object`](/api/object.md), [`objectWithRest`](/api/objectWithRest.md), [`optional`](/api/optional.md), [`picklist`](/api/picklist.md), [`promise`](/api/promise.md), [`record`](/api/record.md), [`set`](/api/set.md), [`strictObject`](/api/strictObject.md), [`strictTuple`](/api/strictTuple.md), [`string`](/api/string.md), [`symbol`](/api/symbol.md), [`tuple`](/api/tuple.md), [`tupleWithRest`](/api/tupleWithRest.md), [`undefined`](/api/undefined.md), [`undefinedable`](/api/undefinedable.md), [`union`](/api/union.md), [`unknown`](/api/unknown.md), [`variant`](/api/variant.md), [`void`](/api/void.md)

### Methods

[`assert`](/api/assert.md), [`config`](/api/config.md), [`fallback`](/api/fallback.md), [`keyof`](/api/keyof.md), [`message`](/api/message.md), [`omit`](/api/omit.md), [`partial`](/api/partial.md), [`pick`](/api/pick.md), [`pipe`](/api/pipe.md), [`required`](/api/required.md), [`unwrap`](/api/unwrap.md)
