screepers / Screeps-Typescript-Declarations

The repository for *Screeps's* TypeScript type definitions.
69 stars 44 forks source link

Create extendable interfaces for built-in Memory objects #61

Closed seancl closed 7 years ago

seancl commented 8 years ago

Fixes issue #60 . Feedback welcome!

seancl commented 8 years ago

Hmm, I just realized that this makes the implicit assumption that a room / creep / flag / spawn will be storing an object in its memory slot. It's technically possible to save anything in the memory - that is, Game.spawns.Spawn1.memory = 5; appears to be totally valid. I'm open to other ideas on how to allow the user to apply an interface to the default memory objects.

NhanHo commented 8 years ago

Hey! Sorry I'm being swarmed this week. I'm gonna take a look at this asap!

seancl commented 8 years ago

After taking another look at this I've made a few minor changes:

I would like to get input on whether to add a union to {} wherever the type is used, to show that the memory can always be an empty object. This would probably result in needing to null check any value pulled from memory, which could be obnoxious, but is technically true. I am leaning toward not doing this, and instead allowing people to decide for themselves if they should make all members of the interface optional (to force null checking) or not.

Dessix commented 7 years ago

Closed due to being out of date. We will likely replace these with completely empty interfaces that can be extended in user code through interface merging, rather than keeping the any lines. Users can declare their own memory layout, as we're moving away from Any typing as much as possible.