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