We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
find*()
!!!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.
This change would ban random cast from results of find*(). If you do not use "type predicate filter", then you have to use as.
as
For example
{ { // @ts-expect-error const towers: StructureTower[] = creep.pos.findInRange(FIND_STRUCTURES, 2, { filter: (s) => s.structureType === STRUCTURE_EXTENSION, }); towers[0].attack(creep); } { // @ts-expect-error const tower1: StructureTower | null = creep.pos.findClosestByPath([] as AnyStructure[], { filter: (s) => s.structureType === STRUCTURE_EXTENSION, }); tower1?.attack(creep); } { // @ts-expect-error const tower2: StructureTower | null = creep.pos.findClosestByRange(FIND_STRUCTURES, { filter: (s) => s.structureType === STRUCTURE_SPAWN, }); tower2?.attack(creep); } // using `as` on your own risk { // $ExpectType StructureTower[] const towers: StructureTower[] = creep.pos.findInRange(FIND_STRUCTURES, 2, { filter: (s) => s.structureType === STRUCTURE_EXTENSION, }) as StructureTower[]; towers[0].attack(creep); //no Error. TS trusts you } }
You can use "type predicate filter" to narrow the union type if you do not want to use as
const isStructureType = <T extends StructureConstant>(structureType: T) => { return (structure: AnyStructure): structure is ConcreteStructure<T> => { return structure.structureType === structureType; }; }; { let towers = creep.pos.findInRange([] as AnyStructure[], 2, { filter: isStructureType(STRUCTURE_TOWER), }); towers[0].attack(creep); // ok } { let tower = creep.pos.findClosestByPath([] as AnyStructure[], { filter: isStructureType(STRUCTURE_TOWER), }); tower?.attack(creep); // ok } { let tower = creep.pos.findClosestByRange([] as AnyStructure[], { filter: isStructureType(STRUCTURE_TOWER), }); tower?.attack(creep); // ok }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Part2: Ban random cast for results of
find*()
!!!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
This change would ban random cast from results of
find*()
. If you do not use "type predicate filter", then you have to useas
.For example
You can use "type predicate filter" to narrow the union type if you do not want to use
as
The text was updated successfully, but these errors were encountered: