Skip to content

Conversation

@sparr
Copy link

@sparr sparr commented Nov 23, 2025

Brief Description

Similar to the Id<T> type, this PR distinguishes between non-interchangeable names (Creep.name, Spawn.name, Room.name, etc) using a unique tagged type.

Also similar to the Id type, this adds a bit of annoyance when using explicit name constants, which I think is a worthwhile tradeoff for the safety from using the wrong strings to index the various lookups by name, etc.

I opted to not type the name parameter to the various create...() functions. The requested name for a new creep doesn't become a Name<Creep> until there's a Creep for it to be associated with on a later tick.

Checklists

  • Test passed
  • Coding style (indentation, etc)
  • Edits have been made to src/ files not index.d.ts
  • Run npm run compile to update index.d.ts

Copy link

@ShuP1 ShuP1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To limit the breaking change, we might duplicate functions and mark old ones as deprecated like getObjectById 886e141#diff-f2fe192fa328d8936d876c22b13504f6b724f79712e08aa9164711caca136827R1556-R1568


{
for (const creepName of Object.keys(Game.creeps)) {
for (const creepName of Object.keys(Game.creeps) as Array<keyof typeof Game.creeps>) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ugly and a breaking change 😢

Could be better with

export function iterKeys<K extends string, V>(d: Partial<Record<K, V>> | Record<K, V>) {
  return Object.keys(d) as unknown as readonly K[]
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am constantly re-surprised by typescript's Object.keys() not producing typed keys from a known-typed object.

@sparr sparr mentioned this pull request Nov 26, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants