【发布时间】:2019-04-13 10:56:45
【问题描述】:
我正在尝试在 Typescript 中为矩阵编写接口,
我找不到将Array<Array<number>> 类型描述为接口的方法。
const matrix:Array<Array<number>> = [
[0,0,0],
[1,1,1],
[0,1,0],
]
相反,我想要类似的东西
//dosen't work
interface Imatrix {
[index:number]:Array<number>
}
然后可以在与 Imatrix 一起使用的函数中使用
function draw(matrix:Imatrix){
matrix.forEach(()=>{
//some code
})
}
draw(matrix)
当我这样做时,我得到错误 Property 'forEach' does not exist on type 'Imatrix'.ts(2339)
【问题讨论】:
标签: typescript types interface