相关疑难解决方法(0)

如何在打字稿中使用带有元组的array.map?

每当我array.map在元组上使用时,Typescript 都会将其推断为通用数组。例如,这里有一些简单的 3x3 数独游戏:

const _ = ' ' // a "Blank"

type Blank = typeof _

type Cell = number | Blank

type Three = [Cell, Cell, Cell]

type Board = [Three, Three, Three]

const initialBoard: Board = [
    [_, 1, 3],
    [3, _, 1],
    [1, _, _],
]

// Adds a `2` to the first cell on the first row
function applyMove(board: Board): Board {
    // errors here
    const newBoard: Board =  board.map((row: Three, index: number) …
Run Code Online (Sandbox Code Playgroud)

tuples typescript

7
推荐指数
2
解决办法
2397
查看次数

标签 统计

tuples ×1

typescript ×1