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

Add missing index.d.ts files to typedefs #204

Closed A-nd-y closed 1 year ago

A-nd-y commented 1 year ago

Hi!

With openhab 3.3 I started to rewrite all my rules with typescript. for this I use the npm package "openhab". Unfortunately without manual rework in node-module i get the following build error:

error TS2688: Cannot find type definition file for 'items'.
  The file is in the program because:
    Entry point for implicit type library 'items'
error TS2688: Cannot find type definition file for 'metadata'.
  The file is in the program because:
    Entry point for implicit type library 'metadata'
error TS2688: Cannot find type definition file for 'things'.
  The file is in the program because:
    Entry point for implicit type library 'things'

But if i create simple index.d.ts files in the folders

node_modules/openhab/types/items node_modules/openhab/types/metadata node_modules/openhab/types/things

all errors are gone and the output is generated. Apparently the behavior is still the same with the current package version (3.1.2). If you could add the missing index.d.ts files, I would be grateful.

florian-h05 commented 1 year ago

Can you please show me the code that leads to these errors? I have an idea what’s the problem …

sfriedle commented 1 year ago

The generated type declarations are not fully TypeScript-conform at the moment. I've run into this a few weeks ago, trying to use the openhab module in a TypeScript project. I started to fix this issues and got it to work. I've created a branch of my changes, but it is now some commits behind the current main, because I didn't had the time to complete a pr.

I've also added a npm script to test the generated type declarations (compile it with tsc), which could be run during the test stage.

@florian-h05 I could rebase my branch to the current main and incorporate the changes to type declarations, which happened in main during the last time.

florian-h05 commented 1 year ago

@sfriedle Would be great to get some type definitions additions, so yes, please rebase and open a PR. I’m not sure if your branch also included type definitions for Rule Builder, that would be really great.

A-nd-y commented 1 year ago

Hi!

After some research I found the cause of the errors:

When I started developing the rules in Typescript, version 1.2.3 of the package was current. But in the package.json of this version there was no types property. So I manually added the typeRoots to tsconfig.json. And that was the whole problem.

Now that the types property is present in packes.json, I was able to revert the changes to the typeRoots and everything is fine.

So nothing needs to be fixed Sorry!