screepers / typed-screeps

Strong TypeScript declarations for the game Screeps.
MIT License
189 stars 77 forks source link

Argument in the filter function of `findClosestByRange` can not be inferred #219

Closed DiamondMofeng closed 1 year ago

DiamondMofeng commented 1 year ago

Bug description

(type of var fromStructures is AnyStoreStructure[])

Argument in the filter function in the option of findClosestByRange has an implicit any type

图片

While in findClosestByPath, this argument is typed correctly

图片

Sample code (if available)

let fromStructures = [] as AnyStoreStructure[]
let creep = {} as Creep
{
  let target = creep.pos.findClosestByPath(fromStructures, {
    //OK `s` here is inferred as `AnyStoreStructure`
    filter: (s) => {
      return s.structureType === STRUCTURE_CONTAINER;
    }
  });
}

{
  let target = creep.pos.findClosestByRange(fromStructures, {
    //!Error `s` here has an implicit `any` type
    filter: (s) => {
      return s.structureType === STRUCTURE_CONTAINER;
    }
  });
}

Your Environment