News for hackers. Stuff that matters.
Re:Rust const generics MVP hits beta by ksbrooksjr on Friday February 26, 2021 @08:14PM (#26281759)
You can do it like this:

  type RequiredKeys<O, K extends keyof O> = Omit<O, K> & Required<Pick<O, K>>
  type Person = {
    name?: string
    age?: number
  }
  type RequiredName = RequiredKeys<Person, 'name'>
The opposite (making some of the fields optional, without affecting the rest) would be written like this:

  type OptionalKeys<O, K extends keyof O> = Omit<O, K> & Partial<Pick<O, K>>

There are no comments on this comment yet.