Create strongly typed array of arrays in TypeScript

前端 未结 4 1734
我在风中等你
我在风中等你 2021-02-03 16:43

In a language like C# I can declare a list of lists like:

List> list_of_lists;

Is there a similar way to declare a strong

相关标签:
4条回答
  • 2021-02-03 17:01

    @Eugene you can use something like Array<Array<[string, number]>> to define a Map type

    0 讨论(0)
  • 2021-02-03 17:16

    You do it exactly like in Java/C#, e.g. (in a class):

    class SomeClass {
        public someVariable: Array<Array<AnyTypeYouWant>>;
    }
    

    Or as a standalone variable:

    var someOtherVariable: Array<Array<AnyTypeYouWant>>;
    
    0 讨论(0)
  • 2021-02-03 17:16

    The simplest is:

    x: Array<Array<Any>>
    

    And, if you need something more complex, you can do something like this:

    y: Array<Array<{z:int, w:string, r:Time}>>
    
    0 讨论(0)
  • 2021-02-03 17:25

    int is not a type in TypeScript. You probably want to use number:

    var listOfLists : number[][];
    
    0 讨论(0)
提交回复
热议问题