Screeps-Typescript-Declarations icon indicating copy to clipboard operation
Screeps-Typescript-Declarations copied to clipboard

helpers.ts LookAtResultMatrix interface

Open Strategic-Link-Consulting opened this issue 9 years ago • 4 comments

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?

NhanHo avatar Apr 19 '16 07:04 NhanHo

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 avatar Apr 20 '16 01:04 dunkndonuts

@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?

NhanHo avatar Apr 21 '16 14:04 NhanHo

I adjusted my code to if(!_.some(area[<string>rowPos][colPos], (lookAt: LookAtResult ) => The compiler liked that.

rogerreeder avatar May 18 '16 02:05 rogerreeder