Skip to content

Commit

Permalink
Fix #252: lookForAtArea matrix result type. (#253)
Browse files Browse the repository at this point in the history
* Fix lookForAtArea matrix result type.

* npm run dtslint

* Modify new test to explicitly match issue description

* Separate tests for default and explicit isArray=false

---------

Co-authored-by: Piotr Paulski <[email protected]>
  • Loading branch information
zyzyzyryxy and Piotr Paulski authored Jan 6, 2024
1 parent 9d727de commit 12cfd11
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1825,9 +1825,9 @@ interface LookAtResultMatrix<K extends LookConstant = LookConstant> {
};
}

interface LookForAtAreaResultMatrix<T, K extends keyof LookAtTypes = keyof LookAtTypes> {
interface LookForAtAreaResultMatrix<T> {
[y: number]: {
[x: number]: Array<LookForAtAreaResult<T, K>>;
[x: number]: T[];
};
}

Expand Down Expand Up @@ -4546,7 +4546,7 @@ interface Room {
bottom: number,
right: number,
asArray?: false,
): LookForAtAreaResultMatrix<AllLookAtTypes[T], T>;
): LookForAtAreaResultMatrix<AllLookAtTypes[T]>;
/**
* Get the given objets in the supplied area.
* @param type One of the LOOK_* constants
Expand Down
12 changes: 11 additions & 1 deletion dist/screeps-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,13 +908,23 @@ function resources(o: GenericStore): ResourceConstant[] {
const x = flags[10];
const y = x[11];
const entry = y[0];
entry.flag.remove();
entry.remove();

const creeps = room.lookForAtArea(LOOK_CREEPS, 10, 10, 20, 20, true);

creeps[0].x;
creeps[0].y;
creeps[0].creep.move(TOP);

// #252
const structuresMatrix = room.lookForAtArea(LOOK_STRUCTURES, 10, 10, 20, 20);

structuresMatrix[15][15].find((s) => s.structureType === STRUCTURE_CONTROLLER);

// #252 with explicit isArray=false
const structuresMatrix2 = room.lookForAtArea(LOOK_STRUCTURES, 10, 10, 20, 20, false);

structuresMatrix2[15][15].find((s) => s.structureType === STRUCTURE_CONTROLLER);
}

// StoreDefinition
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ interface LookAtResultMatrix<K extends LookConstant = LookConstant> {
};
}

interface LookForAtAreaResultMatrix<T, K extends keyof LookAtTypes = keyof LookAtTypes> {
interface LookForAtAreaResultMatrix<T> {
[y: number]: {
[x: number]: Array<LookForAtAreaResult<T, K>>;
[x: number]: T[];
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ interface Room {
bottom: number,
right: number,
asArray?: false,
): LookForAtAreaResultMatrix<AllLookAtTypes[T], T>;
): LookForAtAreaResultMatrix<AllLookAtTypes[T]>;
/**
* Get the given objets in the supplied area.
* @param type One of the LOOK_* constants
Expand Down

0 comments on commit 12cfd11

Please sign in to comment.