Screeps-Typescript-Declarations
Screeps-Typescript-Declarations copied to clipboard
helpers.ts LookAtResultMatrix interface
Think it should be declared as a string for named array, compiler was balking til I changed it.
interface LookAtResultMatrix {
[coord: string]: LookAtResultMatrix|LookAtResult[]
}
Hi, Sorry for the late reply.
Can you give me an example of code that the compiler will complain with coord being number? Looking at the screeps docs (http://support.screeps.com/hc/en-us/articles/203079011-Room#lookForAtArea), the result is a 2d array with both indices being number. I'm not sure which usage will cause a compile time error?
Error is src\Prototypes\RoomPosition.ts(37,24): error TS2345: Argument of type 'LookAtResultMatrix | LookAtResult[] | LookAtResult' is not assignable to parameter of type 'Dictionary<LookAtResult>'. Type 'LookAtResultMatrix' is not assignable to type 'Dictionary<LookAtResult>'. Index signature is missing in type 'LookAtResultMatrix'.
for (var rowPos in area) {
for (var colPos in area[rowPos]) {
var items = area[rowPos][colPos];
if(!_.some(items, (lookAt: LookAtResult ) =>
lookAt.type === "constructionSite"
|| lookAt.type === "exit"
|| lookAt.type === "source"
|| lookAt.type === "structure"
|| (ignoreCreeps ? false : lookAt.type === "creep")
|| (lookAt.type === "terrain" && lookAt.terrain === "wall"))) {
var checkPos: RoomPosition = room.getPositionAt(Number(colPos), Number(rowPos));
room.createFlag(checkPos.x, checkPos.y, undefined, COLOR_YELLOW, COLOR_YELLOW).toString();
routableTiles[checkPos.getId()] = checkPos;
}
}
}
@dunkndonuts : That code compiles normal for me. And I can't figure out how to reproduce the problem still. Any chance you can get a simple snippet for it?
I adjusted my code to
if(!_.some(area[<string>rowPos][colPos], (lookAt: LookAtResult ) =>
The compiler liked that.