TypeScript

July 5, 2026 · View on GitHub

node-gtk can generate TypeScript declarations for the libraries you use, straight from the GObject-Introspection typelibs installed on your machine — so the types always match your actual library versions and node-gtk's own runtime shape (camelCase methods, signal callbacks, nullability, etc.).

# generates ./node_modules/.node-gtk-types (a hidden, git-ignored cache)
npx node-gtk generate-types Gtk-4.0 Adw-1

The command emits one declaration file per namespace (plus the full dependency closure) and a node-gtk.d.ts shim. Point your tsconfig.json at it:

{
  "compilerOptions": {
    "moduleResolution": "node16",
    "paths": { "node-gtk": ["./node_modules/.node-gtk-types/node-gtk.d.ts"] }
  }
}

Then gi.require is fully typed — the namespace is inferred from the string arguments:

import * as gi from 'node-gtk'

const Gtk = gi.require('Gtk', '4.0')   // typed as the Gtk-4.0 namespace
const win = new Gtk.ApplicationWindow({ title: 'Hello', defaultWidth: 400 })
win.on('close-request', () => false)   // signal name + callback are typed

The direct gi: import form is typed too — the generated shim declares each gi:<Namespace>-<version> module, so its default export is the namespace:

import Gtk from 'gi:Gtk-4.0'           // typed as the Gtk-4.0 namespace
const win = new Gtk.ApplicationWindow({ title: 'Hello', defaultWidth: 400 })

You get typed constructor properties (including inherited and interface ones), camelCase methods with real return types, GI nullability, typed signal overloads, enums, bigint for 64-bit integers, out-parameters surfaced as the return value, and cross-namespace types. GNOME's API documentation is included as JSDoc (with @param/@returns), so editors show it on hover — this reads the .gir files installed by the libraries' -dev/-devel packages; pass --no-docs for leaner output if they aren't installed or you don't want them.

Because the output is a generated cache under node_modules, add a postinstall script so it regenerates on install:

{ "scripts": { "postinstall": "node-gtk generate-types Gtk-4.0 Adw-1" } }

Run npx node-gtk generate-types --help for options.