Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ interface Creep extends RoomObject {
* - OK: The operation has been cancelled successfully.
* - ERR_NOT_FOUND: The order with the specified name is not found.
*/
cancelOrder(methodName: string): OK | ERR_NOT_FOUND;
cancelOrder(methodName: MethodKey<Creep>): OK | ERR_NOT_FOUND;
/**
* Claim a controller.
*
Expand Down Expand Up @@ -2325,6 +2325,10 @@ declare namespace Tag {
type Id<T extends _HasId> = string & Tag.OpaqueTag<T>;

type fromId<T> = T extends Id<infer R> ? R : never;

type MethodKey<T> = {
[K in keyof T]: T[K] extends Function ? K : never;
}[keyof T];
/**
* `InterShardMemory` object provides an interface for communicating between shards.
*
Expand Down Expand Up @@ -4034,7 +4038,7 @@ interface PowerCreep extends RoomObject {
* - ERR_BUSY: The power creep is not spawned in the world.
* - ERR_NOT_FOUND: The order with the specified name is not found.
*/
cancelOrder(methodName: string): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_FOUND;
cancelOrder(methodName: MethodKey<PowerCreep>): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_FOUND;
/**
* Delete the power creep permanently from your account.
*
Expand Down
8 changes: 8 additions & 0 deletions dist/screeps-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1424,3 +1424,11 @@ function atackPower(creep: Creep) {
/// @ts-expect-error
const foo = Game.getObjectById<StructureTower>("" as Id<Creep>);
}

// CancelOrder
{
const creep = Game.creeps.sampleCreep;
creep.cancelOrder("repair");
/// @ts-expect-error
creep.cancelOrder("fake");
}
2 changes: 1 addition & 1 deletion src/creep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ interface Creep extends RoomObject {
* - OK: The operation has been cancelled successfully.
* - ERR_NOT_FOUND: The order with the specified name is not found.
*/
cancelOrder(methodName: string): OK | ERR_NOT_FOUND;
cancelOrder(methodName: MethodKey<Creep>): OK | ERR_NOT_FOUND;
/**
* Claim a controller.
*
Expand Down
4 changes: 4 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,3 +478,7 @@ declare namespace Tag {
type Id<T extends _HasId> = string & Tag.OpaqueTag<T>;

type fromId<T> = T extends Id<infer R> ? R : never;

type MethodKey<T> = {
[K in keyof T]: T[K] extends Function ? K : never;
}[keyof T];
2 changes: 1 addition & 1 deletion src/power-creep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ interface PowerCreep extends RoomObject {
* - ERR_BUSY: The power creep is not spawned in the world.
* - ERR_NOT_FOUND: The order with the specified name is not found.
*/
cancelOrder(methodName: string): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_FOUND;
cancelOrder(methodName: MethodKey<PowerCreep>): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_FOUND;
/**
* Delete the power creep permanently from your account.
*
Expand Down