在 TypeScript 中创建强类型数组 [英] Create strongly typed array of arrays in TypeScript

查看:26
本文介绍了在 TypeScript 中创建强类型数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在像 C# 这样的语言中,我可以声明一个列表列表,例如:

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

List<List<int>> list_of_lists;

是否有类似的方法可以在 TypeScript 中声明强类型数组?我尝试了以下方法,但都没有编译.

Is there a similar way to declare a strongly typed array of arrays in TypeScript? I tried the following approaches but neither compiles.

var list_of_lists:int[][];
var list_of_lists:Array<int[]>;

推荐答案

int 不是 TypeScript 中的类型.您可能想使用 number:

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

var listOfLists : number[][];

这篇关于在 TypeScript 中创建强类型数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆