【问题标题】:How to define array type in typescript?如何在打字稿中定义数组类型?
【发布时间】:2017-01-26 18:31:58
【问题描述】:

我在打字稿中使用以下类型的变量:

[[string, string], string][]

有没有办法将它定义为类型,这样我就不必在我的代码中到处重复这个定义?

【问题讨论】:

    标签: arrays typescript


    【解决方案1】:

    你可以定义一个type:

    type stringTuple = [[string, string], string][];
    

    然后像使用类或接口一样使用它:

    var array: stringTuple;
    

    【讨论】:

    • 谢谢!不幸的是,在打字稿文档中很难找到这一点。我希望至少有一个带有关键字索引的语言参考。
    猜你喜欢
    • 2017-04-13
    • 2019-02-10
    • 1970-01-01
    • 2023-01-19
    • 2017-02-20
    • 2019-03-03
    • 1970-01-01
    • 2016-12-25
    • 2018-01-18
    相关资源
    最近更新 更多