openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

Improve Typescript support - ex: Add `Java.type` definitions #387

Open ThaDaVos opened 1 month ago

ThaDaVos commented 1 month ago

Your Environment

Currently when writing rules using Typescript certain types are missing - also it takes some time to get it to load the existing types. But the thing missing most are the Java.* types and intellisense - currently I am running into issues as follows:

TypeError: invokeMember (includes) on java.util.ArrayList@6fddcfbe failed due to: Unknown identifier: includes: TypeError: invokeMember (includes) on java.util.ArrayList@6fddcfbe failed due to: Unknown identifier: includes

I am getting this when I use .includes on some metadata I retrieved with Item.getMetadata() - now I am trying to catch this error by firstly converting it from a Java type to a JS type - but this is only possible if it is a Java type so before doing that I am trying to check if it is - here lies the issue - there's no typing for the Java.* methods at all - not even in the source code here (or I looked over it).

So this feature request is all about improving the typing support for Typescript - or at least, adding the missing types

Dopeyr commented 1 week ago

I'm wondering if a tool like https://github.com/bsorrentino/java2typescript would be useful here.