partial
partial<T extends Record<string, any>>(
schema: ObjectSchema<T, unknown>,
): ObjectSchema<Partial<T>>
partial<T extends Record<string, any>, Key extends string | number | symbol>(
schema: ObjectSchema<T, unknown>,
keys: Key[],
): ObjectSchema<Omit<T, Key> & Partial<Pick<T, Key>>>
Type Parameters
Parameters
schema: ObjectSchema<T, unknown>
keys: Key[]
Returns ObjectSchema<Omit<T, Key> & Partial<Pick<T, Key>>>
Example
import * as x from 'unhoax'
const personSchema = x.object({
name: x.string,
age: x.number,
})
const fullyOptional = partial(personSchema)
const result = fullyOptional.parse({})
result // { success: true, value: {} }
const ageOptional = partial(personSchema, ['age'])
const result = ageOptional.parse({ name: 'hello' })
result // { success: true, value: { name: 'hello' } }
See
object
Example