GlassBricks / typed-factorio

Complete and featureful Typescript defintions for the Factorio modding API
MIT License
33 stars 3 forks source link

reading `LuaControl.force` should only return `LuaForce`, not `LuaForce | string` #10

Closed aSemy closed 2 years ago

aSemy commented 2 years ago

At the moment, reading LuaControl.force returns either a string or LuaForce, but it should only return a LuaForce.

  const player = game.players[playerIndex]

  const force : LuaForce = player.force
  // ERROR 
  // TS2322: Type 'ForceIdentification' is not assignable to type 'LuaForce'. 
  // Type 'string' is not assignable to type 'LuaForce'.

However, assigning a string should be possible.

I think this is probably true anywhere that ForceIdentification can be read, but that's a guess. At a minimum it's also documented as the case for

I also guess this is similar to #7

This is a really minor issue, it's not disrupting me, it's just something I noticed.

https://lua-api.factorio.com/latest/LuaControl.html#LuaControl.force

The force of this entity. Reading will always give a LuaForce, but it is possible to assign either string or LuaForce to this attribute to change the force.

GlassBricks commented 2 years ago

Hi, thanks for the suggestion!

I verified that reading ForceIdentification always yields a LuaForce. A similar thing is true for ItemPrototypeSpecification and TechnologyIdentification.

This change was easy enough to implement, so I did just that.

Released in v0.18.1

aSemy commented 2 years ago

Thanks for the quick fix! It's really nice using this library.