【发布时间】:2019-10-19 12:28:45
【问题描述】:
我正在使用 React/Redux 制作数独网络应用程序。但是我在打字时遇到了一些问题。
当前代码:
// typedef
type Tuple9<T> = [T, T, T, T, T, T, T, T, T];
export type Board = Tuple9<Tuple9<number>>;
// code using board type, I want to fix getEmptyBoard() to more programmatic.
const getEmptyBoard: (() => Board) = () => {
return [
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0]
];
};
我想将getEmptyBoard() 修复为更加程序化。
- 这种情况有好的解决办法吗?
- 如果为 1,解决方案是什么?
【问题讨论】:
标签: javascript arrays typescript multidimensional-array typescript-typings