Type alias WithRequired<T, K>

WithRequired<T, K>: T & {
    [P in K]-?: T[P]
}

This is a type that removes the optional mark from the properties in the K union. This means that they will be required.

Type Parameters

  • T
  • K extends keyof T

Example

type Foo = {
bar?: string
baz?: number
}
type FooRequired = WithRequired<Foo, 'bar' | 'baz'>
// type FooRequired = {
// bar: string
// baz: number
// }