altmp / altv-types

Type definitions for the alt:V JavaScript modules.
https://www.npmjs.com/~vadzz
MIT License
31 stars 74 forks source link

technical: Server: Implement getter & setter for model of entity and … #250

Closed riffy closed 1 year ago

riffy commented 1 year ago

…getter for vehicle

Problem: Since setters of model allow for number or string, providing type safety to declarations must be ensured when getting the model by specfically stating player.model as number every time.

Example:

const map = new Map<number, any>(); // Maps player model hash to something

if (map.has(p.model)) {} // Will throw "Argument of type 'string | number' is not assignable to parameter of type 'number'.
  Type 'string' is not assignable to type 'number'.ts(2345)" and must be circumvented by:

if (map.has(p.model as number)) {}

Getter and setter approach resolves this issue.

C0kkie commented 1 year ago

thank you