Search


Search something to see results

object

Providing a name improves readability of parse errors.

Type Parameters

  • T extends Record<string, Schema<any, unknown>>
  • Input = unknown

Parameters

  • args: [props: T] | [name: string, props: T]

Returns ObjectSchema<{ [Key in keyof T]: TypeOf<T[Key]> }, Input>

import * as x from 'unhoax'

// Use the schema as source of truth:
const personSchema = x.object({
name: x.string,
age: x.number,
})

// you can also name the schema
const personSchema = x.object('Person', { … })
type Person = x.TypeOf<typeof personSchema>

Type Parameters

  • T extends Record<string, any>
  • Input = unknown

Parameters

  • args: [props: PropsOf<T>] | [name: string, props: PropsOf<T>]

Returns ObjectSchema<T, Input>

import * as x from 'unhoax'

type Person = { name: string, age: number }
const personSchema = x.object<Person>({
name: x.string,
age: x.number,
})
// you can also name the schema for better error readability
const personSchema = x.object<Person>('Person', { … })