Is it possible to require only some specified key in an object using type mapping and conditional type?

后端 未结 1 964
终归单人心
终归单人心 2020-12-12 06:57

There is a type from a 3rd party:

interface UpdateRequest {
  data?: ValueRange[];
  options?: Options
}

I want to create a method with th

相关标签:
1条回答
  • 2020-12-12 07:42

    You can use Pick and Required and intersect back with the original type to get back the other optional properties

    type RequireSome<T, K extends keyof T> = Required< Pick<T, K>> & T;
    
    0 讨论(0)
提交回复
热议问题