This change would break nothing. For filters, if they had no error before, they would still be ok after this change.
This means legacy problems would not get solved, for example, the below test cases can not be passed now and after this change.
We'd hope to solve this in the next part.
// worse case, narrowing into incorrect type
// but it is on your own risk if you use `as` to cast the result
{
{
// @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(FIND_STRUCTURES, {
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);
}
}
Part1: Decoupling
FilterOption
andFindConstant
TODO
FilterOption
andFindConstant
find*()
to adapt to newFilterOption
This change would break nothing. For filters, if they had no error before, they would still be ok after this change. This means legacy problems would not get solved, for example, the below test cases can not be passed now and after this change. We'd hope to solve this in the next part.