athombv / homey-web-api-issues

This issue tracker is for Homey Developers using the Web API.
4 stars 1 forks source link

[TypeScript] `HomeyAPIxxx.ManagerDevices.Device` misses properties (`capabilities`, `capabilitiesObj`...) #29

Open OlivierZal opened 1 year ago

OlivierZal commented 1 year ago

Fact that HomeyAPIV2.ManagerDevices.Device is typed as object raises errors for such lines of code:

const capability: string = 'target_temperature'
const value: any = device.capabilitiesObj[capability]?.value
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. ​typescript(7053)
  No index signature with a parameter of type 'string' was found on type '{}'.

or

const value: any = device.capabilitiesObj.target_temperature?.value
Property 'target_temperature' does not exist on type 'object'. ​typescript(2339)
jeroenwienk commented 1 year ago

I think you mean the problem is that capabilitiesObj is types as any?

OlivierZal commented 1 year ago

Yes @jeroenwienk, now it's any but before homey-api@3.0.0 it was object.

The problem is that the type Device is not complete, as you can see on the following screenshots: Property 'capabilities' does not exist on type 'Device'.ts(2339) Property 'capabilitiesObj' does not exist on type 'Device'.ts(2339)

Capture d’écran 2023-07-24 à 23 25 45 Capture d’écran 2023-07-24 à 23 25 28