Skip to content

Indexed access type

Daisho Komiyama edited this page Nov 1, 2022 · 1 revision

The basics

type Invalid = {
  status: number
  message: string
}

type FormError<T> = { [k: string]: T } // <- index signature

const formError: FormError<Invalid> = {}

formError.name.message = 'Name must be at least two characters'
formError.name.status = 400

formError.password.message = 'Password must be at least eight characters'
formError.password.status = 400
Clone this wiki locally