The Id<T>
type was added to assist situations like this simple example.
interface CreepMemory {
sourceId: Id<Source>
}
let source = Game.getObjectById(creep.memory.sourceId)
In this example, the type of source
would be Source
(or null) because the type of the game object can be known by the type of the Id.
In this way, you don't need to use something like as Source
to type assert it. Consider treating object Ids as something that is typed and not generic strings.