From 7fd4c7ea40cdcd6a5baf5c9e9eb689f5c4ea50d0 Mon Sep 17 00:00:00 2001 From: "Clarence \"Sparr\" Risher" Date: Sun, 23 Nov 2025 01:11:19 -0500 Subject: [PATCH] Type cancelOrder methodName parameter to method keys of Creep/PowerCreep --- dist/index.d.ts | 8 ++++++-- dist/screeps-tests.ts | 8 ++++++++ src/creep.ts | 2 +- src/helpers.ts | 4 ++++ src/power-creep.ts | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 73e6f58..2c66b5b 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -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): OK | ERR_NOT_FOUND; /** * Claim a controller. * @@ -2325,6 +2325,10 @@ declare namespace Tag { type Id = string & Tag.OpaqueTag; type fromId = T extends Id ? R : never; + +type MethodKey = { + [K in keyof T]: T[K] extends Function ? K : never; +}[keyof T]; /** * `InterShardMemory` object provides an interface for communicating between shards. * @@ -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): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_FOUND; /** * Delete the power creep permanently from your account. * diff --git a/dist/screeps-tests.ts b/dist/screeps-tests.ts index caa026e..2b4fef6 100644 --- a/dist/screeps-tests.ts +++ b/dist/screeps-tests.ts @@ -1424,3 +1424,11 @@ function atackPower(creep: Creep) { /// @ts-expect-error const foo = Game.getObjectById("" as Id); } + +// CancelOrder +{ + const creep = Game.creeps.sampleCreep; + creep.cancelOrder("repair"); + /// @ts-expect-error + creep.cancelOrder("fake"); +} diff --git a/src/creep.ts b/src/creep.ts index b535ada..aa15c70 100644 --- a/src/creep.ts +++ b/src/creep.ts @@ -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): OK | ERR_NOT_FOUND; /** * Claim a controller. * diff --git a/src/helpers.ts b/src/helpers.ts index 583bb26..ffdff16 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -478,3 +478,7 @@ declare namespace Tag { type Id = string & Tag.OpaqueTag; type fromId = T extends Id ? R : never; + +type MethodKey = { + [K in keyof T]: T[K] extends Function ? K : never; +}[keyof T]; diff --git a/src/power-creep.ts b/src/power-creep.ts index 9f80114..f6dba65 100644 --- a/src/power-creep.ts +++ b/src/power-creep.ts @@ -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): OK | ERR_NOT_OWNER | ERR_BUSY | ERR_NOT_FOUND; /** * Delete the power creep permanently from your account. *