当 Iterable
class Grid<T extends Tile> {
tiles = new Map<T>();
setTile(tile: T) {
this.tiles.set(tile.toString(), tile);
}
constructor();
constructor(coords: Iterable<Coords>); // enforce T = Tile in this case
constructor(tiles: Iterable<T>);
constructor(input?: Iterable<T> | Iterable<Coords>) {
if (!input) return;
for (const t of input) {
if (t instanceof Tile) {
this.setTile(t);
} else {
this.setTile(new Tile(coord)); // ts(2345) error here
}
}
}
}