【问题标题】:How to change the name of a type key selected using Pick?如何更改使用 Pick 选择的类型键的名称?
【发布时间】:2022-11-04 06:06:14
【问题描述】:

我有这种类型:

type Item = {
  title: string
}

我想Pick title 属性在另一个类型定义中使用它:

type NewItem = Pick<Item, 'title'>

但是,在NewType 中,我希望将title 命名为newTitle。我该怎么做呢?

【问题讨论】:

    标签: typescript


    【解决方案1】:

    我什至不会再使用Pick

    type Item = {
      title: string
    };
    
    type NewItem = {
        newTitle: Item["title"];
    };
    

    Playground

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-29
      • 2012-01-21
      • 2015-03-19
      相关资源
      最近更新 更多