Gr3q / types-gjs

Typescript definitions for GJS - Gnome JavaScript
MIT License
7 stars 2 forks source link

[Feature Request] Use ES6 Module #6

Open jonath92 opened 2 years ago

jonath92 commented 2 years ago

The way of importing CJS or GJS module is very special and very uncommon nowadays. It is much more common to use ES6 Modules. The most annoying thing of the GJS variant, is that I don't get any auto suggestion from my IDE (VSC) when I type something.:

image

Ideally the IDE would suggest me to import Label from gi/St. With externals we can map globals to modules in webpack, e.g. instead of "importing" the Label constructor with the help of object destructuring of imports.gi.St we can import it from gi/St (see https://stackoverflow.com/a/45239697/11603006). But only changing the settings in webpack is not sufficient as this doesn't help us to get the correct types. I tried a little bit to achieve this by changing some settings in the tsconfig but AFAICS this is not possible (although I might be wrong). I think the only way to achieve this is to change the types directly which I guess is thanks to your generator not that difficult.

I haven't yet spent any time on your generator and it doesn't have the highest priority for me at the moment. So I really would love to see that feature but I am not willing to implement at my own in the foreseeable future. What do you think @Gr3q?

Gr3q commented 2 years ago

I didn't really think about it because I though it to be impossible. The problem is that they are in the variable imports, so it has to end up destructuring that instead of a regular import.

So I would have to find a way to fake module exports for the declarations and then transform the imports back in actual code so it still works.

This would probably requires modifying the generated declarations in a way that they would no longer map to the actual introspection docs and/or they would not be usable without webpack.

Anyway, it's worth trying to get it to work