ts a 类型全部属性均为可选属性,如何能快速得到一个新类型,此类型中 key 均为 a 类型中的 key,但均为必选属性?

有类型 a 如:

interface a {
  name?: string,
  age?: number,
  gender?: number,
  height?: number
}

想快速得到类型 b 如:

interface b {
  name: string,
  age: number
}

想请教下各位大佬有没有简便些的办法?

阅读 3.3k
1 个回答

Required<Type>

Constructs a type consisting of all properties of Type set to required. The opposite of Partial.

先使用 Required 操作符,它是 Partial 的逆运算。
再使用 PickOmit

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题