Skip to content

Commit

Permalink
Fix return types
Browse files Browse the repository at this point in the history
  • Loading branch information
tiennou committed Feb 2, 2025
1 parent 1f73abf commit 7748900
Show file tree
Hide file tree
Showing 11 changed files with 261 additions and 133 deletions.
196 changes: 130 additions & 66 deletions dist/index.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/screeps-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ function resources(o: GenericStore): ResourceConstant[] {
const exits = room.find(FIND_EXIT);

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

const towers = room.find<StructureTower>(FIND_MY_STRUCTURES, {
filter: (structure) => {
Expand Down
38 changes: 24 additions & 14 deletions src/creep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ interface Creep extends RoomObject {
*
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART
*/
attack(target: AnyCreep | Structure): CreepActionReturnCode;
attack(target: AnyCreep | Structure): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
/**
* Decreases the controller's downgrade or reservation timer for 1 tick per
* every 5 `CLAIM` body parts (so the creep must have at least 5x`CLAIM`).
Expand All @@ -95,7 +95,7 @@ interface Creep extends RoomObject {
*
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE, ERR_NO_BODYPART, ERR_TIRED
*/
attackController(target: StructureController): CreepActionReturnCode;
attackController(target: StructureController): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_TIRED | ERR_NO_BODYPART;
/**
* Build a structure at the target construction site using carried energy.
* Needs WORK and CARRY body parts.
Expand All @@ -105,7 +105,7 @@ interface Creep extends RoomObject {
* @param target The target construction site to be built.
* @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
*/
build(target: ConstructionSite): CreepActionReturnCode | ERR_NOT_ENOUGH_RESOURCES | ERR_RCL_NOT_ENOUGH;
build(target: ConstructionSite): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
/**
* Cancel the order given during the current game tick.
* @param methodName The name of a creep's method to be cancelled.
Expand All @@ -122,7 +122,7 @@ interface Creep extends RoomObject {
* @param target The target controller object.
* @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
*/
claimController(target: StructureController): CreepActionReturnCode | ERR_FULL | ERR_GCL_NOT_ENOUGH;
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;
/**
* Dismantles any (even hostile) structure returning 50% of the energy spent on its repair.
*
Expand All @@ -131,19 +131,19 @@ interface Creep extends RoomObject {
* The target has to be at adjacent square to the creep.
* @param target The target structure.
*/
dismantle(target: Structure): CreepActionReturnCode;
dismantle(target: Structure): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
/**
* Drop this resource on the ground.
* @param resourceType One of the RESOURCE_* constants.
* @param amount The amount of resource units to be dropped. If omitted, all the available carried amount is used.
*/
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES;
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
/**
* 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.
* @param target The target room controller.
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_BUSY, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_TARGET, ERR_NOT_IN_RANGE
*/
generateSafeMode(target: StructureController): CreepActionReturnCode;
generateSafeMode(target: StructureController): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE;
/**
* Get the quantity of live body parts of the given type. Fully damaged parts do not count.
* @param type A body part type, one of the following body part constants: MOVE, WORK, CARRY, ATTACK, RANGED_ATTACK, HEAL, TOUGH, CLAIM
Expand All @@ -159,7 +159,7 @@ interface Creep extends RoomObject {
* The target has to be at an adjacent square to the creep.
* @param target The source object to be harvested.
*/
harvest(target: Source | Mineral | Deposit): CreepActionReturnCode | ERR_NOT_FOUND | ERR_NOT_ENOUGH_RESOURCES;
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;
/**
* Heal self or another creep. It will restore the target creep’s damaged body parts function and increase the hits counter.
*
Expand All @@ -168,14 +168,14 @@ interface Creep extends RoomObject {
* The target has to be at adjacent square to the creep.
* @param target The target creep object.
*/
heal(target: AnyCreep): CreepActionReturnCode;
heal(target: AnyCreep): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
/**
* Move the creep one square in the specified direction or towards a creep that is pulling it.
*
* Requires the MOVE body part if not being pulled.
* @param direction The direction to move in (`TOP`, `TOP_LEFT`...)
*/
move(direction: DirectionConstant): CreepMoveReturnCode;
move(direction: DirectionConstant): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_ARGS | ERR_TIRED | ERR_NO_BODYPART;
move(target: Creep): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
/**
* Move the creep using the specified predefined path. Needs the MOVE body part.
Expand Down Expand Up @@ -215,7 +215,7 @@ interface Creep extends RoomObject {
* 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.
* @param target The target object to be picked up.
*/
pickup(target: Resource): CreepActionReturnCode | ERR_FULL;
pickup(target: Resource): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
/**
* 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.
*
Expand Down Expand Up @@ -294,7 +294,11 @@ interface Creep extends RoomObject {
* @param resourceType One of the RESOURCE_* constants
* @param amount The amount of resources to be transferred. If omitted, all the available carried amount is used.
*/
transfer(target: AnyCreep | Structure, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
transfer(
target: AnyCreep | Structure,
resourceType: ResourceConstant,
amount?: number,
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
/**
* Upgrade your controller to the next level using carried energy.
*
Expand All @@ -309,7 +313,9 @@ interface Creep extends RoomObject {
* The cumulative effect of all the creeps performing upgradeController in the current tick is taken into account.
* @param target The target controller object to be upgraded.
*/
upgradeController(target: StructureController): ScreepsReturnCode;
upgradeController(
target: StructureController,
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
/**
* Withdraw resources from a structure, a tombstone or a ruin.
*
Expand All @@ -322,7 +328,11 @@ interface Creep extends RoomObject {
* @param resourceType The target One of the RESOURCE_* constants..
* @param amount The amount of resources to be transferred. If omitted, all the available amount is used.
*/
withdraw(target: Structure | Tombstone | Ruin, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
withdraw(
target: Structure | Tombstone | Ruin,
resourceType: ResourceConstant,
amount?: number,
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
}

interface CreepConstructor extends _Constructor<Creep>, _ConstructorById<Creep> {}
Expand Down
12 changes: 8 additions & 4 deletions src/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ interface Market {
* @param orderId The order ID as provided in Game.market.orders
* @returns Result Code: OK, ERR_INVALID_ARGS
*/
cancelOrder(orderId: string): ScreepsReturnCode;
cancelOrder(orderId: string): OK | ERR_INVALID_ARGS;
/**
* Change the price of an existing order. If `newPrice` is greater than old price, you will be charged `(newPrice-oldPrice)*remainingAmount*0.05` credits.
* @param orderId The order ID as provided in Game.market.orders
* @param newPrice The new order price.
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_NOT_ENOUGH_RESOURCES, ERR_INVALID_ARGS
*/
changeOrderPrice(orderId: string, newPrice: number): ScreepsReturnCode;
changeOrderPrice(orderId: string, newPrice: number): OK | ERR_NOT_OWNER | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
/**
* Create a market order in your terminal. You will be charged `price*amount*0.05` credits when the order is placed.
*
Expand Down Expand Up @@ -77,15 +77,19 @@ interface Market {
*
* @returns Result Code: OK, ERR_NOT_OWNER, ERR_NOT_ENOUGH_RESOURCES, ERR_FULL, ERR_INVALID_ARGS, ERR_TIRED
*/
deal(orderId: string, amount: number, yourRoomName?: string): ScreepsReturnCode;
deal(
orderId: string,
amount: number,
yourRoomName?: string,
): OK | ERR_NOT_OWNER | ERR_NOT_ENOUGH_RESOURCES | ERR_FULL | ERR_INVALID_ARGS | ERR_TIRED;
/**
* Add more capacity to an existing order. It will affect `remainingAmount` and `totalAmount` properties. You will be charged `price*addAmount*0.05` credits.
* Extending the order doesn't update its expiration time.
* @param orderId The order ID as provided in Game.market.orders
* @param addAmount How much capacity to add. Cannot be a negative value.
* @returns One of the following codes: `OK`, `ERR_NOT_ENOUGH_RESOURCES`, `ERR_INVALID_ARGS`
*/
extendOrder(orderId: string, addAmount: number): ScreepsReturnCode;
extendOrder(orderId: string, addAmount: number): OK | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
/**
* Get other players' orders currently active on the market.
* @param filter (optional) An object or function that will filter the resulting list using the lodash.filter method.
Expand Down
2 changes: 1 addition & 1 deletion src/path-finder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ interface CostMatrix {
* @param y Y position in the room.
* @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.
*/
set(x: number, y: number, cost: number): undefined;
set(x: number, y: number, cost: number): void;
/**
* Get the cost of a position in this CostMatrix.
* @param x X position in the room.
Expand Down
33 changes: 27 additions & 6 deletions src/power-creep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ interface PowerCreep extends RoomObject {
* @param resourceType One of the RESOURCE_* constants.
* @param amount The amount of resource units to be dropped. If omitted, all the available carried amount is used.
*/
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES;
drop(resourceType: ResourceConstant, amount?: number): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_ARGS;
/**
* Enable power usage in this room. The room controller should be at adjacent tile.
* @param controller The room controller
Expand All @@ -106,7 +106,7 @@ interface PowerCreep extends RoomObject {
* Requires the MOVE body part if not being pulled.
* @param direction The direction to move in (`TOP`, `TOP_LEFT`...)
*/
move(direction: DirectionConstant): CreepMoveReturnCode;
move(direction: DirectionConstant): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
move(target: Creep): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
/**
* Move the creep using the specified predefined path. Needs the MOVE body part.
Expand Down Expand Up @@ -136,7 +136,7 @@ interface PowerCreep extends RoomObject {
moveTo(
target: RoomPosition | { pos: RoomPosition },
opts?: MoveToOpts,
): CreepMoveReturnCode | ERR_NO_PATH | ERR_INVALID_TARGET | ERR_NOT_FOUND;
): OK | ERR_NOT_OWNER | ERR_NO_PATH | ERR_BUSY | ERR_NOT_FOUND | ERR_INVALID_TARGET;
/**
* Toggle auto notification when the creep is under attack. The notification will be sent to your account email. Turned on by default.
* @param enabled Whether to enable notification or disable.
Expand Down Expand Up @@ -181,15 +181,32 @@ interface PowerCreep extends RoomObject {
* @param resourceType One of the RESOURCE_* constants
* @param amount The amount of resources to be transferred. If omitted, all the available carried amount is used.
*/
transfer(target: AnyCreep | Structure, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
transfer(
target: AnyCreep | Structure,
resourceType: ResourceConstant,
amount?: number,
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
/**
* 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.
*/
upgrade(power: PowerConstant): OK | ERR_NOT_OWNER | ERR_NOT_ENOUGH_RESOURCES | ERR_FULL | ERR_INVALID_ARGS;
/**
* Apply one of the creep's powers on the specified target.
*/
usePower(power: PowerConstant, target?: RoomObject): ScreepsReturnCode;
usePower(
power: PowerConstant,
target?: RoomObject,
):
| OK
| ERR_NOT_OWNER
| ERR_BUSY
| ERR_NOT_ENOUGH_RESOURCES
| ERR_INVALID_TARGET
| ERR_FULL
| ERR_NOT_IN_RANGE
| ERR_INVALID_ARGS
| ERR_TIRED
| ERR_NO_BODYPART;
/**
* Withdraw resources from a structure, tombstone, or ruin.
*
Expand All @@ -202,7 +219,11 @@ interface PowerCreep extends RoomObject {
* @param resourceType The target One of the RESOURCE_* constants..
* @param amount The amount of resources to be transferred. If omitted, all the available amount is used.
*/
withdraw(target: Structure | Tombstone | Ruin, resourceType: ResourceConstant, amount?: number): ScreepsReturnCode;
withdraw(
target: Structure | Tombstone | Ruin,
resourceType: ResourceConstant,
amount?: number,
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE | ERR_INVALID_ARGS;
}

interface PowerCreepConstructor extends _Constructor<PowerCreep>, _ConstructorById<PowerCreep> {
Expand Down
2 changes: 1 addition & 1 deletion src/raw-memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface RawMemory {
* Request memory segments using the list of their IDs. Memory segments will become available on the next tick in RawMemory.segments object.
* @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.
*/
setActiveSegments(ids: number[]): undefined;
setActiveSegments(ids: number[]): void;
/**
* Request a memory segment of another user.
*
Expand Down
9 changes: 7 additions & 2 deletions src/room-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ interface RoomPosition {
* * STRUCTURE_WALL
* * STRUCTURE_LINK
*/
createConstructionSite(structureType: BuildableStructureConstant): ScreepsReturnCode;
createConstructionSite(
structureType: BuildableStructureConstant,
): OK | ERR_NOT_OWNER | ERR_INVALID_TARGET | ERR_FULL | ERR_INVALID_ARGS | ERR_RCL_NOT_ENOUGH;
/**
* Create new ConstructionSite at the specified location.
* @param structureType One of the following constants:
Expand All @@ -42,7 +44,10 @@ interface RoomPosition {
* * STRUCTURE_LINK
* @param name The name of the structure, for structures that support it (currently only spawns).
*/
createConstructionSite(structureType: STRUCTURE_SPAWN, name?: string): ScreepsReturnCode;
createConstructionSite(
structureType: STRUCTURE_SPAWN,
name?: string,
): OK | ERR_NOT_OWNER | ERR_INVALID_TARGET | ERR_FULL | ERR_INVALID_ARGS | ERR_RCL_NOT_ENOUGH;
/**
* Create new Flag at the specified location.
* @param name The name of a new flag.
Expand Down
Loading

0 comments on commit 7748900

Please sign in to comment.