Skip to content

Commit

Permalink
Feat: Setting the Order type to ORDER_BUY | ORDER_SELL instead of str…
Browse files Browse the repository at this point in the history
…ing (#255)

* Update Order interface in market.ts

Setting the type to ORDER_BUY | ORDER_SELL instead of string

* Updating index.d.ts

* test: add test for hardcoded string literal value
  • Loading branch information
DollarAkshay authored Feb 3, 2024
1 parent 12cfd11 commit 8957b7b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3173,7 +3173,7 @@ interface Order {
id: string;
created: number;
active?: boolean;
type: string;
type: ORDER_BUY | ORDER_SELL;
resourceType: MarketResourceConstant;
roomName?: string;
amount: number;
Expand Down
15 changes: 15 additions & 0 deletions dist/screeps-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,21 @@ function resources(o: GenericStore): ResourceConstant[] {
Game.market.createOrder({ type: ORDER_SELL, resourceType: RESOURCE_GHODIUM, price: 9.95, totalAmount: 10000, roomName: "W1N1" });
Game.market.createOrder({ type: ORDER_SELL, resourceType: RESOURCE_GHODIUM, price: 9.95, totalAmount: 10000 });

// Testing the hardcoded string literal value of the `type` field
{
// error
Game.market.createOrder({
// @ts-expect-error
type: "BUY",
resourceType: RESOURCE_GHODIUM,
price: 9.95,
totalAmount: 10000,
});

// okay
Game.market.createOrder({ type: "buy", resourceType: RESOURCE_GHODIUM, price: 9.95, totalAmount: 10000 });
}

// Game.market.deal(orderId, amount, [yourRoomName])
Game.market.deal("57cd2b12cda69a004ae223a3", 1000, "W1N1");

Expand Down
2 changes: 1 addition & 1 deletion src/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ interface Order {
id: string;
created: number;
active?: boolean;
type: string;
type: ORDER_BUY | ORDER_SELL;
resourceType: MarketResourceConstant;
roomName?: string;
amount: number;
Expand Down

0 comments on commit 8957b7b

Please sign in to comment.