简体   繁体   English

如何键入将 arrays 数组作为输入的 function

[英]How to type a function that takes an array of arrays as input

I have a function drawSnake which is called as follows:我有一个 function drawSnake ,它的名称如下:

 drawSnake(
[
 [0, 0],
 [0, 1],
 [0, 2],
 [0, 3],
 [0, 4],
]
);

How can I type the input for this function?如何键入此 function 的输入?

I have tried something like Array<Array<[number, number]>> but it doesn't seem to be right.我尝试过类似Array<Array<[number, number]>>的方法,但它似乎不正确。

function drawSnake(snake: ???) {
    ...
  }

as stated on comments (@VLAZ).如评论(@VLAZ)所述。 You can do it like this你可以这样做

function drawSnake(snake: Array<[number, number]>) {
    ...
  }

Thanks to @VLAZ and @thedude in the comments above, this can be solved in 2 ways:感谢上面评论中的@VLAZ 和@thedude,这可以通过两种方式解决:

#1: #1:

   Array<[number, number]>

#2: #2:

   [number, number][]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何优化采用数组并集的函数中的类型? - How to refine types in function that takes union of arrays? 检查函数是否采用数组或单值输入 - Check if a function takes an array or single valued input 如何在 typescript 中创建一个 function ,它将数组作为用户输入以及如何查找数组长度? - How to create a function in typescript which takes array as an user input and how to find array length? 如何从指令中设置输入类型文本的值,该指令从数组中获取随机值 - How to set value of input type text from a Directive, that takes a random value from an array 如何使用递归编写 function,该递归采用 2 个整数并返回包含 2 个输入整数之间的整数的数组 - How to write a function using recursion that takes 2 integers and returns an array containing integers between the 2 input integers 如何编写一个包含2个字符串的函数,并将它们添加到相应数组的BEGINNING中 - how to write a function that takes 2 strings, and add them to the BEGINNING of the respective arrays Javascript:编写一个接受数组的函数,然后返回仅包含唯一数字且仅删除数组的数组 - Javascript: Write a function that takes in an array, and then returns an array with only unique numbers, only arrays removed 如果输入是JavaScript中的数组数组,如何传播参数 - How to spread arguments if the input is an array of arrays in JavaScript 如何在不嵌套数组的情况下将此数组传递给已经具有其他输入的函数? - How do I pass this array to a function which already has other input, without nesting the arrays? 将数组作为输入的javascript函数,将每个数组元素加1,然后返回值增加的新数组不起作用 - javascript function that takes array as input, increases each array element by 1 and returns new array with increased values not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM