Skip to content

Commit e628c65

Browse files
committed
Fix return types
1 parent cb2e5e8 commit e628c65

11 files changed

+281
-135
lines changed

dist/index.d.ts

+140-67
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

+30-18
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ interface Creep extends RoomObject {
125125
* - ERR_NOT_IN_RANGE: The target is too far away.
126126
* - ERR_NO_BODYPART: There are no ATTACK body parts in this creep’s body.
127127
*/
128-
attack(target: AnyCreep | Structure): CreepActionReturnCode;
128+
attack(target: AnyCreep | Structure): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
129129
/**
130130
* Attack a controller.
131131
*
@@ -143,7 +143,7 @@ interface Creep extends RoomObject {
143143
* - ERR_TIRED: You have to wait until the next attack is possible.
144144
* - ERR_NO_BODYPART: There are not enough CLAIM body parts in this creep’s body.
145145
*/
146-
attackController(target: StructureController): CreepActionReturnCode;
146+
attackController(target: StructureController): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_TIRED | ERR_NO_BODYPART;
147147
/**
148148
* Build a structure at the target construction site using carried energy.
149149
*
@@ -160,7 +160,7 @@ interface Creep extends RoomObject {
160160
* - ERR_NOT_IN_RANGE: The target is too far away.
161161
* - ERR_NO_BODYPART: There are no WORK body parts in this creep’s body.
162162
*/
163-
build(target: ConstructionSite): CreepActionReturnCode | ERR_NOT_ENOUGH_RESOURCES | ERR_RCL_NOT_ENOUGH;
163+
build(target: ConstructionSite): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
164164
/**
165165
* Cancel the order given during the current game tick.
166166
* @param methodName The name of a creep's method to be cancelled.
@@ -188,7 +188,7 @@ interface Creep extends RoomObject {
188188
* - ERR_NO_BODYPART: There are no CLAIM body parts in this creep’s body.
189189
* - ERR_GCL_NOT_ENOUGH: Your Global Control Level is not enough.
190190
*/
191-
claimController(target: StructureController): CreepActionReturnCode | ERR_FULL | ERR_GCL_NOT_ENOUGH;
191+
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;
192192
/**
193193
* Dismantles any structure that can be constructed (even hostile) returning 50% of the energy spent on its repair.
194194
*
@@ -204,7 +204,7 @@ interface Creep extends RoomObject {
204204
* - ERR_NOT_IN_RANGE: The target is too far away.
205205
* - ERR_NO_BODYPART: There are no WORK body parts in this creep’s body.
206206
*/
207-
dismantle(target: Structure): CreepActionReturnCode;
207+
dismantle(target: Structure): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
208208
/**
209209
* Drop this resource on the ground.
210210
*
@@ -217,7 +217,7 @@ interface Creep extends RoomObject {
217217
* - ERR_NOT_ENOUGH_RESOURCES: The creep does not have the given amount of resources.
218218
* - ERR_INVALID_ARGS: The resourceType is not a valid RESOURCE_* constants.
219219
*/
220-
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES;
220+
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
221221
/**
222222
* Add one more available safe mode activation to a room controller.
223223
*
@@ -231,7 +231,7 @@ interface Creep extends RoomObject {
231231
* - ERR_INVALID_TARGET: The target is not a valid controller object.
232232
* - ERR_NOT_IN_RANGE: The target is too far away.
233233
*/
234-
generateSafeMode(target: StructureController): CreepActionReturnCode;
234+
generateSafeMode(target: StructureController): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE;
235235
/**
236236
* Get the quantity of live body parts of the given type.
237237
*
@@ -259,7 +259,7 @@ interface Creep extends RoomObject {
259259
* - ERR_TIRED: The extractor or the deposit is still cooling down.
260260
* - ERR_NO_BODYPART: There are no WORK body parts in this creep’s body.
261261
*/
262-
harvest(target: Source | Mineral | Deposit): CreepActionReturnCode | ERR_NOT_FOUND | ERR_NOT_ENOUGH_RESOURCES;
262+
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;
263263
/**
264264
* Heal self or another creep.
265265
*
@@ -277,7 +277,7 @@ interface Creep extends RoomObject {
277277
* - ERR_NOT_IN_RANGE: The target is too far away.
278278
* - ERR_NO_BODYPART: There are no HEAL body parts in this creep’s body.
279279
*/
280-
heal(target: AnyCreep): CreepActionReturnCode;
280+
heal(target: AnyCreep): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
281281
/**
282282
* Move the creep one square in the specified direction or towards a creep that is pulling it.
283283
*
@@ -293,7 +293,7 @@ interface Creep extends RoomObject {
293293
* - ERR_TIRED: The fatigue indicator of the creep is non-zero.
294294
* - ERR_NO_BODYPART: There are no MOVE body parts in this creep’s body.
295295
*/
296-
move(direction: DirectionConstant): CreepMoveReturnCode;
296+
move(direction: DirectionConstant): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_ARGS | ERR_TIRED | ERR_NO_BODYPART;
297297
move(target: Creep): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
298298
/**
299299
* Move the creep using the specified predefined path.
@@ -353,7 +353,7 @@ interface Creep extends RoomObject {
353353
* - ERR_NOT_IN_RANGE: The target is too far away.
354354
* - ERR_NO_BODYPART: There are no CARRY body parts in this creep’s body.
355355
*/
356-
pickup(target: Resource): CreepActionReturnCode | ERR_FULL;
356+
pickup(target: Resource): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
357357
/**
358358
* Allow another creep to follow this creep.
359359
*
@@ -387,7 +387,7 @@ interface Creep extends RoomObject {
387387
* - ERR_NOT_IN_RANGE: The target is too far away.
388388
* - ERR_NO_BODYPART: There are no RANGED_ATTACK body parts in this creep’s body.
389389
*/
390-
rangedAttack(target: AnyCreep | Structure): CreepActionReturnCode;
390+
rangedAttack(target: AnyCreep | Structure): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
391391
/**
392392
* Heal another creep at a distance.
393393
*
@@ -403,7 +403,7 @@ interface Creep extends RoomObject {
403403
* - ERR_NOT_IN_RANGE: The target is too far away.
404404
* - ERR_NO_BODYPART: There are no HEAL body parts in this creep’s body.
405405
*/
406-
rangedHeal(target: AnyCreep): CreepActionReturnCode;
406+
rangedHeal(target: AnyCreep): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
407407
/**
408408
* A ranged attack against all hostile creeps or structures within 3 squares range.
409409
*
@@ -429,7 +429,9 @@ interface Creep extends RoomObject {
429429
* - ERR_NOT_IN_RANGE: The target is too far away.
430430
* - ERR_NO_BODYPART: There are no WORK body parts in this creep’s body.
431431
*/
432-
repair(target: Structure): CreepActionReturnCode | ERR_NOT_ENOUGH_RESOURCES;
432+
repair(
433+
target: Structure,
434+
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
433435
/**
434436
* Temporarily block a neutral controller from claiming by other players.
435437
*
@@ -447,7 +449,7 @@ interface Creep extends RoomObject {
447449
* - ERR_NOT_IN_RANGE: The target is too far away.
448450
* - ERR_NO_BODYPART: There are no CLAIM body parts in this creep’s body.
449451
*/
450-
reserveController(target: StructureController): CreepActionReturnCode;
452+
reserveController(target: StructureController): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
451453
/**
452454
* Display a visual speech balloon above the creep with the specified message.
453455
*
@@ -504,7 +506,11 @@ interface Creep extends RoomObject {
504506
* - ERR_NOT_IN_RANGE: The target is too far away.
505507
* - ERR_INVALID_ARGS: The resourceType is not one of the {@link ResourceConstant RESOURCE_*} constants, or the amount is incorrect.
506508
*/
507-
transfer(target: AnyCreep | Structure, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
509+
transfer(
510+
target: AnyCreep | Structure,
511+
resourceType: ResourceConstant,
512+
amount?: number,
513+
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
508514
/**
509515
* Upgrade your controller to the next level using carried energy.
510516
*
@@ -526,7 +532,9 @@ interface Creep extends RoomObject {
526532
* - ERR_NOT_IN_RANGE: The target is too far away.
527533
* - ERR_NO_BODYPART: There are no WORK body parts in this creep’s body.
528534
*/
529-
upgradeController(target: StructureController): ScreepsReturnCode;
535+
upgradeController(
536+
target: StructureController,
537+
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
530538
/**
531539
* Withdraw resources from a structure, a tombstone or a ruin.
532540
*
@@ -549,7 +557,11 @@ interface Creep extends RoomObject {
549557
* - ERR_NOT_IN_RANGE: The target is too far away.
550558
* - ERR_INVALID_ARGS: The resourceType is not one of the {@link ResourceConstant RESOURCE_*} constants, or the amount is incorrect.
551559
*/
552-
withdraw(target: Structure | Tombstone | Ruin, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
560+
withdraw(
561+
target: Structure | Tombstone | Ruin,
562+
resourceType: ResourceConstant,
563+
amount?: number,
564+
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
553565
}
554566

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

src/market.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ interface Market {
4747
* - OK: The operation has been scheduled successfully.
4848
* - ERR_INVALID_ARGS: The order ID is not valid.
4949
*/
50-
cancelOrder(orderId: string): ScreepsReturnCode;
50+
cancelOrder(orderId: string): OK | ERR_INVALID_ARGS;
5151
/**
5252
* Change the price of an existing order.
5353
*
@@ -60,7 +60,7 @@ interface Market {
6060
* - ERR_NOT_ENOUGH_RESOURCES: You don't have enough credits to pay a fee.
6161
* - ERR_INVALID_ARGS: The arguments provided are invalid.
6262
*/
63-
changeOrderPrice(orderId: string, newPrice: number): ScreepsReturnCode;
63+
changeOrderPrice(orderId: string, newPrice: number): OK | ERR_NOT_OWNER | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
6464
/**
6565
* Create a market order in your terminal.
6666
*
@@ -103,7 +103,11 @@ interface Market {
103103
* - ERR_INVALID_ARGS: The arguments provided are invalid.
104104
* - ERR_TIRED: The target terminal is still cooling down.
105105
*/
106-
deal(orderId: string, amount: number, yourRoomName?: string): ScreepsReturnCode;
106+
deal(
107+
orderId: string,
108+
amount: number,
109+
yourRoomName?: string,
110+
): OK | ERR_NOT_OWNER | ERR_NOT_ENOUGH_RESOURCES | ERR_FULL | ERR_INVALID_ARGS | ERR_TIRED;
107111
/**
108112
* Add more capacity to an existing order.
109113
*
@@ -117,7 +121,7 @@ interface Market {
117121
* - ERR_NOT_ENOUGH_RESOURCES: You don't have enough credits to pay a fee.
118122
* - ERR_INVALID_ARGS: The arguments provided are invalid.
119123
*/
120-
extendOrder(orderId: string, addAmount: number): ScreepsReturnCode;
124+
extendOrder(orderId: string, addAmount: number): OK | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
121125
/**
122126
* Get other players' orders currently active on the market.
123127
* @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
@@ -155,7 +155,7 @@ interface CostMatrix {
155155
* @param y Y position in the room.
156156
* @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.
157157
*/
158-
set(x: number, y: number, cost: number): undefined;
158+
set(x: number, y: number, cost: number): void;
159159
/**
160160
* Get the cost of a position in this CostMatrix.
161161
* @param x X position in the room.

src/power-creep.ts

+29-8
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ interface PowerCreep extends RoomObject {
134134
* - ERR_NOT_ENOUGH_RESOURCES: The creep does not have the given amount of energy.
135135
* - ERR_INVALID_ARGS: The resourceType is not a valid {@link ResourceConstant RESOURCE_*} constants.
136136
*/
137-
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES;
137+
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
138138
/**
139139
* Enable power usage in this room.
140140
*
@@ -159,7 +159,7 @@ interface PowerCreep extends RoomObject {
159159
* - ERR_NOT_IN_RANGE: The target creep is too far away
160160
* - ERR_INVALID_ARGS: The provided direction is incorrect.
161161
*/
162-
move(direction: DirectionConstant): CreepMoveReturnCode;
162+
move(direction: DirectionConstant): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
163163
move(target: Creep): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
164164
/**
165165
* Move the creep using the specified predefined path.
@@ -173,7 +173,7 @@ interface PowerCreep extends RoomObject {
173173
* - ERR_NOT_FOUND: The specified path doesn't match the creep's location.
174174
* - ERR_INVALID_ARGS: path is not a valid path array.
175175
*/
176-
moveByPath(path: PathStep[] | RoomPosition[] | string): CreepMoveReturnCode | ERR_NOT_FOUND | ERR_INVALID_ARGS;
176+
moveByPath(path: PathStep[] | RoomPosition[] | string): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_FOUND | ERR_INVALID_ARGS;
177177
/**
178178
* Find the optimal path to the target within the same room and move to it.
179179
*
@@ -196,7 +196,7 @@ interface PowerCreep extends RoomObject {
196196
moveTo(
197197
target: RoomPosition | { pos: RoomPosition },
198198
opts?: MoveToOpts,
199-
): CreepMoveReturnCode | ERR_NO_PATH | ERR_INVALID_TARGET | ERR_NOT_FOUND;
199+
): OK | ERR_NOT_OWNER | ERR_NO_PATH | ERR_BUSY | ERR_NOT_FOUND | ERR_INVALID_TARGET;
200200
/**
201201
* Toggle auto notification when the creep is under attack.
202202
*
@@ -222,7 +222,7 @@ interface PowerCreep extends RoomObject {
222222
* - ERR_FULL: The creep cannot receive any more resource.
223223
* - ERR_NOT_IN_RANGE: The target is too far away.
224224
*/
225-
pickup(target: Resource): CreepActionReturnCode | ERR_FULL;
225+
pickup(target: Resource): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE;
226226
/**
227227
* Rename the power creep.
228228
*
@@ -300,7 +300,11 @@ interface PowerCreep extends RoomObject {
300300
* - ERR_NOT_IN_RANGE: The target is too far away.
301301
* - ERR_INVALID_ARGS: The resourceType is not one of the {@link ResourceConstant RESOURCE_*} constants, or the amount is incorrect.
302302
*/
303-
transfer(target: AnyCreep | Structure, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
303+
transfer(
304+
target: AnyCreep | Structure,
305+
resourceType: ResourceConstant,
306+
amount?: number,
307+
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
304308
/**
305309
* Upgrade the creep, adding a new power ability to it or increasing the level of the existing power.
306310
*
@@ -331,7 +335,20 @@ interface PowerCreep extends RoomObject {
331335
* - ERR_TIRED: The power ability is still on cooldown.
332336
* - ERR_NO_BODYPART: The creep doesn't have the specified power ability.
333337
*/
334-
usePower(power: PowerConstant, target?: RoomObject): ScreepsReturnCode;
338+
usePower(
339+
power: PowerConstant,
340+
target?: RoomObject,
341+
):
342+
| OK
343+
| ERR_NOT_OWNER
344+
| ERR_BUSY
345+
| ERR_NOT_ENOUGH_RESOURCES
346+
| ERR_INVALID_TARGET
347+
| ERR_FULL
348+
| ERR_NOT_IN_RANGE
349+
| ERR_INVALID_ARGS
350+
| ERR_TIRED
351+
| ERR_NO_BODYPART;
335352
/**
336353
* Withdraw resources from a structure, tombstone, or ruin.
337354
*
@@ -353,7 +370,11 @@ interface PowerCreep extends RoomObject {
353370
* - ERR_NOT_IN_RANGE: The target is too far away.
354371
* - ERR_INVALID_ARGS: The resourceType is not one of the {@link ResourceConstant RESOURCE_*} constants, or the amount is incorrect.
355372
*/
356-
withdraw(target: Structure | Tombstone | Ruin, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
373+
withdraw(
374+
target: Structure | Tombstone | Ruin,
375+
resourceType: ResourceConstant,
376+
amount?: number,
377+
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
357378
}
358379

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

src/raw-memory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ interface RawMemory {
5656
* @param ids An array of segment IDs.
5757
* @throws if `ids` isn't an array, more than 10 segments are active, or the ids aren't all integers.
5858
*/
59-
setActiveSegments(ids: number[]): undefined;
59+
setActiveSegments(ids: number[]): void;
6060
/**
6161
* Request a memory segment of another user.
6262
*

src/room-position.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ interface RoomPosition {
3131
* - ERR_INVALID_ARGS: The location is incorrect.
3232
* - ERR_RCL_NOT_ENOUGH: Room Controller Level insufficient.
3333
*/
34-
createConstructionSite(structureType: BuildableStructureConstant): ScreepsReturnCode;
34+
createConstructionSite(
35+
structureType: BuildableStructureConstant,
36+
): OK | ERR_NOT_OWNER | ERR_INVALID_TARGET | ERR_FULL | ERR_INVALID_ARGS | ERR_RCL_NOT_ENOUGH;
3537
/**
3638
* Create a new {@link ConstructionSite} at the specified location.
3739
* @param structureType One of {@link BuildableStructureConstant Buildable STRUCTURE_*}.
@@ -44,7 +46,10 @@ interface RoomPosition {
4446
* - ERR_INVALID_ARGS: The location is incorrect.
4547
* - ERR_RCL_NOT_ENOUGH: Room Controller Level insufficient.
4648
*/
47-
createConstructionSite(structureType: STRUCTURE_SPAWN, name?: string): ScreepsReturnCode;
49+
createConstructionSite(
50+
structureType: STRUCTURE_SPAWN,
51+
name?: string,
52+
): OK | ERR_NOT_OWNER | ERR_INVALID_TARGET | ERR_FULL | ERR_INVALID_ARGS | ERR_RCL_NOT_ENOUGH;
4853
/**
4954
* Create a new {@link Flag} at the specified location.
5055
* @param name The name of a new flag.

0 commit comments

Comments
 (0)