Skip to content

gjsify/ts-for-gir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2,069 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TS for GIR

TypeScript type definition generator for GObject introspection GIR files

ts-for-gir is a robust TypeScript type definitions generator that improves the development experience of GJS projects. It has been completely rewritten over time to provide a more complete and accurate TypeScript representation of the GObject introspection interfaces. With ts-for-gir, developers can now benefit from TypeScript's strong typing and improved code navigation, making it easier to build robust and powerful applications with GJS.

Browse the full TypeScript API Documentation for GLib, GTK, GStreamer, and many other GNOME libraries.

Getting Started

Install the latest LTS version of Node.js — we recommend using NVM. The fastest path to a working GJS + TypeScript project:

npx @ts-for-gir/cli create my-app

That scaffolds a ready-to-run starter with esbuild, tsconfig.json, and a minimal Gtk/Adwaita main.ts. Pick a template interactively — or pass --template <id>:

  • types-npm — uses the pre-generated @girs/* NPM packages (fastest start)
  • types-locally — generates types directly into ./@types/, no @girs/* dependencies
  • types-workspace — npm workspace layout with locally-generated @girs/* as workspace packages
cd my-app
npm start

Using the CLI directly

If you already have a project and just need type definitions, invoke ts-for-gir without scaffolding:

npx @ts-for-gir/cli generate Gtk-4.0

Run npx @ts-for-gir/cli --help for all commands. See the CLI documentation for detailed options and advanced usage.

Debug Generation Issues: If you encounter type generation problems, enable the reporter and use the analyze command:

npx @ts-for-gir/cli generate Gtk-4.0 --reporter
npx @ts-for-gir/cli analyze -f ./ts-for-gir-report.json

Showcase

GNOME Applications

GNOME Shell Extensions

Example Projects

Looking for a starting point? These example projects demonstrate how to use the TypeScript definitions with various bundlers:

More examples with screenshots and descriptions can be found in the Examples directory. For information on using the examples with different CLI options, refer to the CLI documentation.

NPM Packages

If you are only interested in the types and do not want to generate them yourself, you can use our pre-generated NPM packages. For example, if you want to develop a Gtk4 application with GJS, it is enough to install the corresponding NPM packages:

npm install @girs/gjs @girs/gtk-4.0 --save
import '@girs/gjs'
import '@girs/gjs/dom'
import '@girs/gtk-4.0'

import Gtk from 'gi://Gtk?version=4.0';

const button = new Gtk.Button();

All pre-generated NPM packages can be found on gjsify/types.

You want your or any other missing GObject introspection based library types to be published on NPM for every release? Then feel free to create an issue for it, we will be happy to include it.

Project Structure

ts-for-gir consists of several packages:

Submodules

This repo contains Git submodules for pre-generated types and documentation:

  • types-dev (branch dev): used during local development. Scripts write generated packages here.
  • types-release (branch main): updated by the release workflow on tags.
  • docs (branch main): generated HTML documentation, deployed to gjsify.github.io/docs.

Useful scripts:

yarn build:types          # generates into ./types-dev
yarn build:types:release  # generates into ./types-release
yarn build:doc            # generates HTML docs into ./docs

Further Information

About

TypeScript type definition generator for GObject introspection interfaces

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors