【发布时间】:2019-08-22 06:51:10
【问题描述】:
TypeScript 新手在这里。我做了一些快速搜索,但无法找到答案。问题是:元组数组的正确定义是什么,其中第一个元组元素是字符串,下一个元素是数字数组?我试过这个:
type labeledValuesType = [string, number[]]
constructor(headings: string[], rows: Array<labeledValuesType>) {...
但在 VS Code 中,当我将鼠标悬停在传递给构造函数调用的第二个参数(行)上时,我看到:
const rows: (string | number[])[][]
它看起来像字符串和数字[] 的并集的二维数组。
【问题讨论】:
-
你能提供一个真实的minimal reproducible example 来证明这个问题吗?在像the TypeScript Playground 这样的独立环境中重现问题是了解我们都在同一页面上的好方法。就目前而言,代码中
rows的类型在我的IDE 中显示为(parameter) rows: [string, number[]][]。也许您正在查看问题中未包含的某些变量的类型?
标签: typescript typescript-typings