This package provides module declarations for some of the most common GJS gir modules (see Gnome JavaScript). With it you will get fully typed imports for the following modules:
gi://Atk?version=1.0gi://GLib?version=2.0gi://GModule?version=2.0gi://GObject?version=2.0gi://Gdk?version=3.0gi://Gdk?version=4.0gi://GdkPixbuf?version=2.0gi://Gio?version=2.0gi://Graphene?version=1.0gi://Gsk?version=4.0gi://Gtk?version=3.0gi://Gtk?version=4.0gi://HarfBuzz?version=0.0gi://Pango?version=1.0gi://PangoCairo?version=1.0gi://Soup?version=2.4gi://Soup?version=3.0gi://cairo?version=1.0gi://freetype2?version=2.0gi://xlib?version=2.0
Additionally a module declaration for system module is included as well as some global functions and variables like globalThis.print(), globalThis.imports, globalThis.pkg etc.
-
Install this package via npm or yarn
-
Add this package to the tsconfig.json typeRoots:
{ "compilerOptions": { "typeRoots": ["node_modules/gjs-esm-types", "node_modules/@types"] } } -
giimports should now be correctly typed:import Gtk from "gi://Gtk?version=3.0"; const window = new Gtk.Window(); // Resolved Type - const window: Gtk.Window;
This package only provides module declarations for imports with a version specifier. If you want your imports to not include the version, add a .d.ts file in your project and define the module declarations in there, similarly to this:
declare module "gi://Gtk" {
import Gtk from "gi://Gtk?version=4.0";
export default Gtk;
}declare module "gi://GLib" {
import GLib from "gi://GLib?version=2.0";
export default GLib;
}declare module "gi://Soup" {
import Soup from "gi://Soup?version=2.4";
export default Soup;
}