Here's a simple code snippet I've been using to create a 2D array:
type cell = {
id: string;
};
const board: cell[][];
board = Array(10)
.fill("")
.map((x) => Array(10).fill(ANY TYPE CAN GO HERE WHY?));
Oddly enough, when I populate the inner array, I can insert any type of data without encountering any errors. Usually, I would expect to only be able to input objects of type cell
. Why is this happening?
I'm aware that I should probably specify a type for Array(10)
, but shouldn't TypeScript then throw an error since "cell" is not included in any union type?
Why isn't type checking enforced in this situation?
Could this convoluted method be causing issues with inferred types?