Open
Description
typed-screeps-arena/dist/game/utils.d.ts
Lines 29 to 32 in 75014a1
The current return type of GameObject[]
doesn't avail its self of being able to discriminate into specific objects. For example, I would expect the following to work:
for (const o of getObjects()) {
if ('body' in o && o.my) {
o.attack(enemy)
}
}
But it doesn't because TypeScript doesn't assume that an array of a base type could be any implementation of it. I propose that a union type be created of all the items that could be returned and getObjects()
returns that type of array.
type AllGameObjects =
| GameObject
| Creep
| Structure
| OwnedStructure
| StructureTower
| StructureSpawn
| StructureContainer
| StructureWall
| StructureExtension
| StructureRampart
| ConstructionSite
| Resource
| Source
| Flag
| ScoreCollector;
export function getObjects(): AllGameObjects[];
Metadata
Metadata
Assignees
Labels
No labels