Skip to content

Commit 7748900

Browse files
committed
Fix return types
1 parent 1f73abf commit 7748900

11 files changed

+261
-133
lines changed

dist/index.d.ts

+130-66
Large diffs are not rendered by default.

dist/screeps-tests.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ function resources(o: GenericStore): ResourceConstant[] {
609609
const exits = room.find(FIND_EXIT);
610610

611611
const creepsHere = room.lookForAt(LOOK_CREEPS, 10, 10);
612-
creepsHere[0].getActiveBodyparts(ATTACK);
612+
if (creepsHere !== ERR_INVALID_ARGS) creepsHere[0].getActiveBodyparts(ATTACK);
613613

614614
const towers = room.find<StructureTower>(FIND_MY_STRUCTURES, {
615615
filter: (structure) => {

src/creep.ts

+24-14
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ interface Creep extends RoomObject {
8585
*
8686
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART
8787
*/
88-
attack(target: AnyCreep | Structure): CreepActionReturnCode;
88+
attack(target: AnyCreep | Structure): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
8989
/**
9090
* Decreases the controller's downgrade or reservation timer for 1 tick per
9191
* every 5 `CLAIM` body parts (so the creep must have at least 5x`CLAIM`).
@@ -95,7 +95,7 @@ interface Creep extends RoomObject {
9595
*
9696
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART, ERR_TIRED
9797
*/
98-
attackController(target: StructureController): CreepActionReturnCode;
98+
attackController(target: StructureController): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_TIRED | ERR_NO_BODYPART;
9999
/**
100100
* Build a structure at the target construction site using carried energy.
101101
* Needs WORK and CARRY body parts.
@@ -105,7 +105,7 @@ interface Creep extends RoomObject {
105105
* @param target The target construction site to be built.
106106
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART, ERR_RCL_NOT_ENOUGH
107107
*/
108-
build(target: ConstructionSite): CreepActionReturnCode | ERR_NOT_ENOUGH_RESOURCES | ERR_RCL_NOT_ENOUGH;
108+
build(target: ConstructionSite): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
109109
/**
110110
* Cancel the order given during the current game tick.
111111
* @param methodName The name of a creep's method to be cancelled.
@@ -122,7 +122,7 @@ interface Creep extends RoomObject {
122122
* @param target The target controller object.
123123
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_FULL, ERR_NOT_IN_RANGE, ERR_NO_BODYPART, ERR_GCL_NOT_ENOUGH
124124
*/
125-
claimController(target: StructureController): CreepActionReturnCode | ERR_FULL | ERR_GCL_NOT_ENOUGH;
125+
claimController(target: StructureController): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_NO_BODYPART | ERR_GCL_NOT_ENOUGH;
126126
/**
127127
* Dismantles any (even hostile) structure returning 50% of the energy spent on its repair.
128128
*
@@ -131,19 +131,19 @@ interface Creep extends RoomObject {
131131
* The target has to be at adjacent square to the creep.
132132
* @param target The target structure.
133133
*/
134-
dismantle(target: Structure): CreepActionReturnCode;
134+
dismantle(target: Structure): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
135135
/**
136136
* Drop this resource on the ground.
137137
* @param resourceType One of the RESOURCE_* constants.
138138
* @param amount The amount of resource units to be dropped. If omitted, all the available carried amount is used.
139139
*/
140-
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES;
140+
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
141141
/**
142142
* Add one more available safe mode activation to a room controller. The creep has to be at adjacent square to the target room controller and have 1000 ghodium resource.
143143
* @param target The target room controller.
144144
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE
145145
*/
146-
generateSafeMode(target: StructureController): CreepActionReturnCode;
146+
generateSafeMode(target: StructureController): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE;
147147
/**
148148
* Get the quantity of live body parts of the given type. Fully damaged parts do not count.
149149
* @param type A body part type, one of the following body part constants: MOVE, WORK, CARRY, ATTACK, RANGED_ATTACK, HEAL, TOUGH, CLAIM
@@ -159,7 +159,7 @@ interface Creep extends RoomObject {
159159
* The target has to be at an adjacent square to the creep.
160160
* @param target The source object to be harvested.
161161
*/
162-
harvest(target: Source | Mineral | Deposit): CreepActionReturnCode | ERR_NOT_FOUND | ERR_NOT_ENOUGH_RESOURCES;
162+
harvest(target: Source | Mineral | Deposit): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_FOUND | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_TIRED | ERR_NO_BODYPART;
163163
/**
164164
* Heal self or another creep. It will restore the target creep’s damaged body parts function and increase the hits counter.
165165
*
@@ -168,14 +168,14 @@ interface Creep extends RoomObject {
168168
* The target has to be at adjacent square to the creep.
169169
* @param target The target creep object.
170170
*/
171-
heal(target: AnyCreep): CreepActionReturnCode;
171+
heal(target: AnyCreep): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
172172
/**
173173
* Move the creep one square in the specified direction or towards a creep that is pulling it.
174174
*
175175
* Requires the MOVE body part if not being pulled.
176176
* @param direction The direction to move in (`TOP`, `TOP_LEFT`...)
177177
*/
178-
move(direction: DirectionConstant): CreepMoveReturnCode;
178+
move(direction: DirectionConstant): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_ARGS | ERR_TIRED | ERR_NO_BODYPART;
179179
move(target: Creep): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
180180
/**
181181
* Move the creep using the specified predefined path. Needs the MOVE body part.
@@ -215,7 +215,7 @@ interface Creep extends RoomObject {
215215
* Pick up an item (a dropped piece of energy). Needs the CARRY body part. The target has to be at adjacent square to the creep or at the same square.
216216
* @param target The target object to be picked up.
217217
*/
218-
pickup(target: Resource): CreepActionReturnCode | ERR_FULL;
218+
pickup(target: Resource): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
219219
/**
220220
* Allow another creep to follow this creep. The fatigue generated for the target's move will be added to the creep instead of the target.
221221
*
@@ -294,7 +294,11 @@ interface Creep extends RoomObject {
294294
* @param resourceType One of the RESOURCE_* constants
295295
* @param amount The amount of resources to be transferred. If omitted, all the available carried amount is used.
296296
*/
297-
transfer(target: AnyCreep | Structure, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
297+
transfer(
298+
target: AnyCreep | Structure,
299+
resourceType: ResourceConstant,
300+
amount?: number,
301+
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
298302
/**
299303
* Upgrade your controller to the next level using carried energy.
300304
*
@@ -309,7 +313,9 @@ interface Creep extends RoomObject {
309313
* The cumulative effect of all the creeps performing upgradeController in the current tick is taken into account.
310314
* @param target The target controller object to be upgraded.
311315
*/
312-
upgradeController(target: StructureController): ScreepsReturnCode;
316+
upgradeController(
317+
target: StructureController,
318+
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
313319
/**
314320
* Withdraw resources from a structure, a tombstone or a ruin.
315321
*
@@ -322,7 +328,11 @@ interface Creep extends RoomObject {
322328
* @param resourceType The target One of the RESOURCE_* constants..
323329
* @param amount The amount of resources to be transferred. If omitted, all the available amount is used.
324330
*/
325-
withdraw(target: Structure | Tombstone | Ruin, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
331+
withdraw(
332+
target: Structure | Tombstone | Ruin,
333+
resourceType: ResourceConstant,
334+
amount?: number,
335+
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
326336
}
327337

328338
interface CreepConstructor extends _Constructor<Creep>, _ConstructorById<Creep> {}

src/market.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ interface Market {
3737
* @param orderId The order ID as provided in Game.market.orders
3838
* @returns Result Code: OK, ERR_INVALID_ARGS
3939
*/
40-
cancelOrder(orderId: string): ScreepsReturnCode;
40+
cancelOrder(orderId: string): OK | ERR_INVALID_ARGS;
4141
/**
4242
* Change the price of an existing order. If `newPrice` is greater than old price, you will be charged `(newPrice-oldPrice)*remainingAmount*0.05` credits.
4343
* @param orderId The order ID as provided in Game.market.orders
4444
* @param newPrice The new order price.
4545
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_ARGS
4646
*/
47-
changeOrderPrice(orderId: string, newPrice: number): ScreepsReturnCode;
47+
changeOrderPrice(orderId: string, newPrice: number): OK | ERR_NOT_OWNER | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
4848
/**
4949
* Create a market order in your terminal. You will be charged `price*amount*0.05` credits when the order is placed.
5050
*
@@ -77,15 +77,19 @@ interface Market {
7777
*
7878
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_NOT_ENOUGH_RESOURCES, ERR_FULL, ERR_INVALID_ARGS, ERR_TIRED
7979
*/
80-
deal(orderId: string, amount: number, yourRoomName?: string): ScreepsReturnCode;
80+
deal(
81+
orderId: string,
82+
amount: number,
83+
yourRoomName?: string,
84+
): OK | ERR_NOT_OWNER | ERR_NOT_ENOUGH_RESOURCES | ERR_FULL | ERR_INVALID_ARGS | ERR_TIRED;
8185
/**
8286
* Add more capacity to an existing order. It will affect `remainingAmount` and `totalAmount` properties. You will be charged `price*addAmount*0.05` credits.
8387
* Extending the order doesn't update its expiration time.
8488
* @param orderId The order ID as provided in Game.market.orders
8589
* @param addAmount How much capacity to add. Cannot be a negative value.
8690
* @returns One of the following codes: `OK`, `ERR_NOT_ENOUGH_RESOURCES`, `ERR_INVALID_ARGS`
8791
*/
88-
extendOrder(orderId: string, addAmount: number): ScreepsReturnCode;
92+
extendOrder(orderId: string, addAmount: number): OK | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
8993
/**
9094
* Get other players' orders currently active on the market.
9195
* @param filter (optional) An object or function that will filter the resulting list using the lodash.filter method.

src/path-finder.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ interface CostMatrix {
130130
* @param y Y position in the room.
131131
* @param cost Cost of this position. Must be a whole number. A cost of 0 will use the terrain cost for that tile. A cost greater than or equal to 255 will be treated as unwalkable.
132132
*/
133-
set(x: number, y: number, cost: number): undefined;
133+
set(x: number, y: number, cost: number): void;
134134
/**
135135
* Get the cost of a position in this CostMatrix.
136136
* @param x X position in the room.

src/power-creep.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ interface PowerCreep extends RoomObject {
9494
* @param resourceType One of the RESOURCE_* constants.
9595
* @param amount The amount of resource units to be dropped. If omitted, all the available carried amount is used.
9696
*/
97-
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES;
97+
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
9898
/**
9999
* Enable power usage in this room. The room controller should be at adjacent tile.
100100
* @param controller The room controller
@@ -106,7 +106,7 @@ interface PowerCreep extends RoomObject {
106106
* Requires the MOVE body part if not being pulled.
107107
* @param direction The direction to move in (`TOP`, `TOP_LEFT`...)
108108
*/
109-
move(direction: DirectionConstant): CreepMoveReturnCode;
109+
move(direction: DirectionConstant): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
110110
move(target: Creep): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
111111
/**
112112
* Move the creep using the specified predefined path. Needs the MOVE body part.
@@ -136,7 +136,7 @@ interface PowerCreep extends RoomObject {
136136
moveTo(
137137
target: RoomPosition | { pos: RoomPosition },
138138
opts?: MoveToOpts,
139-
): CreepMoveReturnCode | ERR_NO_PATH | ERR_INVALID_TARGET | ERR_NOT_FOUND;
139+
): OK | ERR_NOT_OWNER | ERR_NO_PATH | ERR_BUSY | ERR_NOT_FOUND | ERR_INVALID_TARGET;
140140
/**
141141
* Toggle auto notification when the creep is under attack. The notification will be sent to your account email. Turned on by default.
142142
* @param enabled Whether to enable notification or disable.
@@ -181,15 +181,32 @@ interface PowerCreep extends RoomObject {
181181
* @param resourceType One of the RESOURCE_* constants
182182
* @param amount The amount of resources to be transferred. If omitted, all the available carried amount is used.
183183
*/
184-
transfer(target: AnyCreep | Structure, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
184+
transfer(
185+
target: AnyCreep | Structure,
186+
resourceType: ResourceConstant,
187+
amount?: number,
188+
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
185189
/**
186190
* Upgrade the creep, adding a new power ability to it or increasing the level of the existing power. You need one free Power Level in your account to perform this action.
187191
*/
188192
upgrade(power: PowerConstant): OK | ERR_NOT_OWNER | ERR_NOT_ENOUGH_RESOURCES | ERR_FULL | ERR_INVALID_ARGS;
189193
/**
190194
* Apply one of the creep's powers on the specified target.
191195
*/
192-
usePower(power: PowerConstant, target?: RoomObject): ScreepsReturnCode;
196+
usePower(
197+
power: PowerConstant,
198+
target?: RoomObject,
199+
):
200+
| OK
201+
| ERR_NOT_OWNER
202+
| ERR_BUSY
203+
| ERR_NOT_ENOUGH_RESOURCES
204+
| ERR_INVALID_TARGET
205+
| ERR_FULL
206+
| ERR_NOT_IN_RANGE
207+
| ERR_INVALID_ARGS
208+
| ERR_TIRED
209+
| ERR_NO_BODYPART;
193210
/**
194211
* Withdraw resources from a structure, tombstone, or ruin.
195212
*
@@ -202,7 +219,11 @@ interface PowerCreep extends RoomObject {
202219
* @param resourceType The target One of the RESOURCE_* constants..
203220
* @param amount The amount of resources to be transferred. If omitted, all the available amount is used.
204221
*/
205-
withdraw(target: Structure | Tombstone | Ruin, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
222+
withdraw(
223+
target: Structure | Tombstone | Ruin,
224+
resourceType: ResourceConstant,
225+
amount?: number,
226+
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
206227
}
207228

208229
interface PowerCreepConstructor extends _Constructor<PowerCreep>, _ConstructorById<PowerCreep> {

src/raw-memory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ interface RawMemory {
4343
* Request memory segments using the list of their IDs. Memory segments will become available on the next tick in RawMemory.segments object.
4444
* @param ids An array of segment IDs. Each ID should be a number from 0 to 99. Maximum 10 segments can be active at the same time. Subsequent calls of setActiveSegments override previous ones.
4545
*/
46-
setActiveSegments(ids: number[]): undefined;
46+
setActiveSegments(ids: number[]): void;
4747
/**
4848
* Request a memory segment of another user.
4949
*

src/room-position.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ interface RoomPosition {
3030
* * STRUCTURE_WALL
3131
* * STRUCTURE_LINK
3232
*/
33-
createConstructionSite(structureType: BuildableStructureConstant): ScreepsReturnCode;
33+
createConstructionSite(
34+
structureType: BuildableStructureConstant,
35+
): OK | ERR_NOT_OWNER | ERR_INVALID_TARGET | ERR_FULL | ERR_INVALID_ARGS | ERR_RCL_NOT_ENOUGH;
3436
/**
3537
* Create new ConstructionSite at the specified location.
3638
* @param structureType One of the following constants:
@@ -42,7 +44,10 @@ interface RoomPosition {
4244
* * STRUCTURE_LINK
4345
* @param name The name of the structure, for structures that support it (currently only spawns).
4446
*/
45-
createConstructionSite(structureType: STRUCTURE_SPAWN, name?: string): ScreepsReturnCode;
47+
createConstructionSite(
48+
structureType: STRUCTURE_SPAWN,
49+
name?: string,
50+
): OK | ERR_NOT_OWNER | ERR_INVALID_TARGET | ERR_FULL | ERR_INVALID_ARGS | ERR_RCL_NOT_ENOUGH;
4651
/**
4752
* Create new Flag at the specified location.
4853
* @param name The name of a new flag.

0 commit comments

Comments
 (0)