You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This will not be easily merged. Feel free to give your idea on whether we should apply this to our next major version.
TODO
remove overloads about find<StructureType>()
To some point, find<StructureType>() is an explict assertion like as. It does not ensure that you are getting a correct type.
{lettowers=creep.pos.findInRange<StructureTower>([]asAnyStructure[],2,{filter: (s)=>s.structureType===STRUCTURE_SPAWN,});towers[0].attack(creep);// no error, it's on your own risk}
In most cases, you can implement some "safe" "Type Predicate Filter" to avoid mistakes. For example,
When filter is just used for structure types:
constisStructureType=<TextendsStructureConstant>(structureType: T)=>{return(structure: AnyStructure): structure is ConcreteStructure<T>=>{returnstructure.structureType===structureType;};};lettowers=creep.pos.findInRange([]asAnyStructure[],2,{filter: isStructureType(STRUCTURE_TOWER),});towers[0].attack(creep);// ok
for multiple structure types:
exportfunctionincludes<TextendsU,U>(arr: ReadonlyArray<T>,item: U): item is T{returnarr.includes(itemasT);}exportfunctionisStructureTypeAmong<TextendsAnyStructure["structureType"]>(structureTypes: T[]){return(s: AnyStructure): s is ConcreteStructure<T>=>{returnincludes(structureTypes,s.structureType);}}
However, when the conditions become complicated like filtering unfulfilled Spawn,Extension,Tower,..., you can either use an explict assertion, or implement some special "safe" "type predicate filters", like isStoreStructure. It's on your own.
The text was updated successfully, but these errors were encountered:
Part 3 : Ban
find<StructureType>()
!!!THIS IS A BREAKING CHANGE!!!
!!!THIS A BREAKING CHANGE!!!
This will not be easily merged. Feel free to give your idea on whether we should apply this to our next major version.
TODO
find<StructureType>()
To some point,
find<StructureType>()
is an explict assertion likeas
. It does not ensure that you are getting a correct type.In most cases, you can implement some "safe" "Type Predicate Filter" to avoid mistakes. For example,
When filter is just used for structure types:
for multiple structure types:
However, when the conditions become complicated like filtering unfulfilled
Spawn
,Extension
,Tower
,..., you can either use an explict assertion, or implement some special "safe" "type predicate filters", likeisStoreStructure
. It's on your own.The text was updated successfully, but these errors were encountered: