screepers / typed-screeps

Strong TypeScript declarations for the game Screeps.
MIT License
191 stars 77 forks source link

Result of room.lookForAtArea(..., false) is wrongly typed. #252

Closed zyzyzyryxy closed 10 months ago

zyzyzyryxy commented 10 months ago

Room.lookForAtArea can return results in multiple formats. Not all are currently tested and not all are correctly typed.

Expected Behavior

Following code is working and should pass type checking.

Actual Behavior

s is typed as an object with two fields, type and structure. This is not what the game returns. As a result, following misleading error is returned for s.structureType:

Property 'structureType' does not exist on type 'LookForAtAreaResult<Structure, "structure">'. Did you mean 'structure'?ts(2551)

Sample code (if available)

const room = Game.rooms.W33S45, x = 21, y = 23;
room.lookForAtArea(LOOK_STRUCTURES, y, x, y, x)[y][x].find(s => s.structureType === STRUCTURE_CONTROLLER)

Your Environment

zyzyzyryxy commented 10 months ago

I think I fixed it already: https://github.com/screepers/typed-screeps/pull/253