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 cb2e5e8 commit e628c65
Show file tree
Hide file tree
Showing 11 changed files with 281 additions and 135 deletions.
207 changes: 140 additions & 67 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
48 changes: 30 additions & 18 deletions src/creep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_NO_BODYPART: There are no ATTACK body parts in this creep’s body.
*/
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;
/**
* Attack a controller.
*
Expand All @@ -143,7 +143,7 @@ interface Creep extends RoomObject {
* - ERR_TIRED: You have to wait until the next attack is possible.
* - ERR_NO_BODYPART: There are not enough CLAIM body parts in this creep’s body.
*/
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.
*
Expand All @@ -160,7 +160,7 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_NO_BODYPART: There are no WORK body parts in this creep’s body.
*/
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 Down Expand Up @@ -188,7 +188,7 @@ interface Creep extends RoomObject {
* - ERR_NO_BODYPART: There are no CLAIM body parts in this creep’s body.
* - ERR_GCL_NOT_ENOUGH: Your Global Control Level is 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 structure that can be constructed (even hostile) returning 50% of the energy spent on its repair.
*
Expand All @@ -204,7 +204,7 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_NO_BODYPART: There are no WORK body parts in this creep’s body.
*/
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.
*
Expand All @@ -217,7 +217,7 @@ interface Creep extends RoomObject {
* - ERR_NOT_ENOUGH_RESOURCES: The creep does not have the given amount of resources.
* - ERR_INVALID_ARGS: The resourceType is not a valid RESOURCE_* constants.
*/
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.
*
Expand All @@ -231,7 +231,7 @@ interface Creep extends RoomObject {
* - ERR_INVALID_TARGET: The target is not a valid controller object.
* - ERR_NOT_IN_RANGE: The target is too far away.
*/
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.
*
Expand Down Expand Up @@ -259,7 +259,7 @@ interface Creep extends RoomObject {
* - ERR_TIRED: The extractor or the deposit is still cooling down.
* - ERR_NO_BODYPART: There are no WORK body parts in this creep’s body.
*/
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.
*
Expand All @@ -277,7 +277,7 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_NO_BODYPART: There are no HEAL body parts in this creep’s body.
*/
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.
*
Expand All @@ -293,7 +293,7 @@ interface Creep extends RoomObject {
* - ERR_TIRED: The fatigue indicator of the creep is non-zero.
* - ERR_NO_BODYPART: There are no MOVE body parts in this creep’s body.
*/
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.
Expand Down Expand Up @@ -353,7 +353,7 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_NO_BODYPART: There are no CARRY body parts in this creep’s body.
*/
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.
*
Expand Down Expand Up @@ -387,7 +387,7 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_NO_BODYPART: There are no RANGED_ATTACK body parts in this creep’s body.
*/
rangedAttack(target: AnyCreep | Structure): CreepActionReturnCode;
rangedAttack(target: AnyCreep | Structure): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
/**
* Heal another creep at a distance.
*
Expand All @@ -403,7 +403,7 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_NO_BODYPART: There are no HEAL body parts in this creep’s body.
*/
rangedHeal(target: AnyCreep): CreepActionReturnCode;
rangedHeal(target: AnyCreep): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
/**
* A ranged attack against all hostile creeps or structures within 3 squares range.
*
Expand All @@ -429,7 +429,9 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_NO_BODYPART: There are no WORK body parts in this creep’s body.
*/
repair(target: Structure): CreepActionReturnCode | ERR_NOT_ENOUGH_RESOURCES;
repair(
target: Structure,
): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_ENOUGH_RESOURCES | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
/**
* Temporarily block a neutral controller from claiming by other players.
*
Expand All @@ -447,7 +449,7 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_NO_BODYPART: There are no CLAIM body parts in this creep’s body.
*/
reserveController(target: StructureController): CreepActionReturnCode;
reserveController(target: StructureController): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_NOT_IN_RANGE | ERR_NO_BODYPART;
/**
* Display a visual speech balloon above the creep with the specified message.
*
Expand Down Expand Up @@ -504,7 +506,11 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_INVALID_ARGS: The resourceType is not one of the {@link ResourceConstant RESOURCE_*} constants, or the amount is incorrect.
*/
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 @@ -526,7 +532,9 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_NO_BODYPART: There are no WORK body parts in this creep’s body.
*/
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 @@ -549,7 +557,11 @@ interface Creep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_INVALID_ARGS: The resourceType is not one of the {@link ResourceConstant RESOURCE_*} constants, or the amount is incorrect.
*/
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 @@ -47,7 +47,7 @@ interface Market {
* - OK: The operation has been scheduled successfully.
* - ERR_INVALID_ARGS: The order ID is not valid.
*/
cancelOrder(orderId: string): ScreepsReturnCode;
cancelOrder(orderId: string): OK | ERR_INVALID_ARGS;
/**
* Change the price of an existing order.
*
Expand All @@ -60,7 +60,7 @@ interface Market {
* - ERR_NOT_ENOUGH_RESOURCES: You don't have enough credits to pay a fee.
* - ERR_INVALID_ARGS: The arguments provided are invalid.
*/
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.
*
Expand Down Expand Up @@ -103,7 +103,11 @@ interface Market {
* - ERR_INVALID_ARGS: The arguments provided are invalid.
* - ERR_TIRED: The target terminal is still cooling down.
*/
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.
*
Expand All @@ -117,7 +121,7 @@ interface Market {
* - ERR_NOT_ENOUGH_RESOURCES: You don't have enough credits to pay a fee.
* - ERR_INVALID_ARGS: The arguments provided are invalid.
*/
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 @@ -155,7 +155,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
37 changes: 29 additions & 8 deletions src/power-creep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ interface PowerCreep extends RoomObject {
* - ERR_NOT_ENOUGH_RESOURCES: The creep does not have the given amount of energy.
* - ERR_INVALID_ARGS: The resourceType is not a valid {@link ResourceConstant RESOURCE_*} constants.
*/
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.
*
Expand All @@ -159,7 +159,7 @@ interface PowerCreep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target creep is too far away
* - ERR_INVALID_ARGS: The provided direction is incorrect.
*/
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.
Expand All @@ -173,7 +173,7 @@ interface PowerCreep extends RoomObject {
* - ERR_NOT_FOUND: The specified path doesn't match the creep's location.
* - ERR_INVALID_ARGS: path is not a valid path array.
*/
moveByPath(path: PathStep[] | RoomPosition[] | string): CreepMoveReturnCode | ERR_NOT_FOUND | ERR_INVALID_ARGS;
moveByPath(path: PathStep[] | RoomPosition[] | string): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_FOUND | ERR_INVALID_ARGS;
/**
* Find the optimal path to the target within the same room and move to it.
*
Expand All @@ -196,7 +196,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.
*
Expand All @@ -222,7 +222,7 @@ interface PowerCreep extends RoomObject {
* - ERR_FULL: The creep cannot receive any more resource.
* - ERR_NOT_IN_RANGE: The target is too far away.
*/
pickup(target: Resource): CreepActionReturnCode | ERR_FULL;
pickup(target: Resource): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_INVALID_TARGET | ERR_FULL | ERR_NOT_IN_RANGE;
/**
* Rename the power creep.
*
Expand Down Expand Up @@ -300,7 +300,11 @@ interface PowerCreep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_INVALID_ARGS: The resourceType is not one of the {@link ResourceConstant RESOURCE_*} constants, or the amount is incorrect.
*/
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.
*
Expand Down Expand Up @@ -331,7 +335,20 @@ interface PowerCreep extends RoomObject {
* - ERR_TIRED: The power ability is still on cooldown.
* - ERR_NO_BODYPART: The creep doesn't have the specified power ability.
*/
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 @@ -353,7 +370,11 @@ interface PowerCreep extends RoomObject {
* - ERR_NOT_IN_RANGE: The target is too far away.
* - ERR_INVALID_ARGS: The resourceType is not one of the {@link ResourceConstant RESOURCE_*} constants, or the amount is incorrect.
*/
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 @@ -56,7 +56,7 @@ interface RawMemory {
* @param ids An array of segment IDs.
* @throws if `ids` isn't an array, more than 10 segments are active, or the ids aren't all integers.
*/
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 @@ -31,7 +31,9 @@ interface RoomPosition {
* - ERR_INVALID_ARGS: The location is incorrect.
* - ERR_RCL_NOT_ENOUGH: Room Controller Level insufficient.
*/
createConstructionSite(structureType: BuildableStructureConstant): ScreepsReturnCode;
createConstructionSite(
structureType: BuildableStructureConstant,
): OK | ERR_NOT_OWNER | ERR_INVALID_TARGET | ERR_FULL | ERR_INVALID_ARGS | ERR_RCL_NOT_ENOUGH;
/**
* Create a new {@link ConstructionSite} at the specified location.
* @param structureType One of {@link BuildableStructureConstant Buildable STRUCTURE_*}.
Expand All @@ -44,7 +46,10 @@ interface RoomPosition {
* - ERR_INVALID_ARGS: The location is incorrect.
* - ERR_RCL_NOT_ENOUGH: Room Controller Level insufficient.
*/
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 a new {@link Flag} at the specified location.
* @param name The name of a new flag.
Expand Down
Loading

0 comments on commit e628c65

Please sign in to comment.