Limit typescript's Record keys

Viewed 25

Is there a way to restrict a Record to have certain keys, but not make them all required? For example, if I do this:

type Foo = {
  some: number
  keys: string
  here: Date
}

const output: Record<keyof Foo, unknown> = {
}

it'll limit the keys to just what's in Foo, but it requires that the output variable specify all of the keys. I want to make them all optional. Essentially just looking for some compiler help to make sure I don't mistype a key name.

Typescript 4.7.4

0 Answers
Related