【问题标题】:How to get type of key and value of a Map type definition in typescript如何在打字稿中获取 Map 类型定义的键类型和值
【发布时间】:2022-11-02 18:41:55
【问题描述】:

给定一种 Map,例如:

type Foo = Map<string, number>;

有没有办法获得用于keyvalue 的类型?

【问题讨论】:

    标签: typescript


    【解决方案1】:

    它可能是一种(可怕的)方式

    type Foo = Map<string, number>;
    
    type Key = Parameters<Foo["set"]>[0];
    type Value = Parameters<Foo["set"]>[1];
    

    【讨论】:

      猜你喜欢
      • 2021-03-19
      • 1970-01-01
      • 2020-05-09
      • 2019-01-02
      • 2016-12-25
      • 2022-01-25
      • 2021-12-31
      • 2017-04-13
      • 2018-01-18
      相关资源
      最近更新 更多