gr3q / types-gjs Goto Github PK
View Code? Open in Web Editor NEWTypescript definitions for GJS - Gnome JavaScript
License: MIT License
Typescript definitions for GJS - Gnome JavaScript
License: MIT License
Some things just can't be correctly typed due to limits/weird behavior in GJS. I think it would be great to mention this on the readme. Two things I have in mind:
Invalid value 'undefined' for property text in object initializer.
For this code snippet:
const label = new Label({
....
text: getcurrentChannel()?.name // getCurrentChannel can be undefined
})
It is a minor issue but worth to fix at some time in future:
Currently the types don't prevent me to write something like this:
const { Label } = imports.gi.St
const { Text } = imports.gi.Clutter
const label = new Label({
visible: false,
clutter_text: new Text({
use_markup: true
})
})
This is wrong because clutter_text
is readonly. GJS is throwing the following error: [radio@driglu4it]: Property StLabel.clutter-text is not writable
.
I haven't tested if this also effects other classes but as the types are auto generated I guess this to be the case.
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.:
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.