Examples

May 20, 2026 ยท View on GitHub

This directory contains various examples showing how to use TypeScript with GJS applications. Each example demonstrates different libraries, features, and bundlers to help you get started with your own projects.

About the Examples

Each example:

  • Uses TypeScript with GJS
  • Demonstrates TypeScript type definitions generated by ts-for-gir
  • Shows how to configure various bundlers or the TypeScript compiler
  • Can be used as a starting point for your own projects

To use an example:

  1. Go to the example directory
  2. Run gjsify install to install dependencies
  3. Run gjsify run build to build the example
  4. Run gjsify run start to run the example

Note: Examples must be built because GJS cannot execute TypeScript directly. However, the core ts-for-gir packages no longer require building and run directly as TypeScript files.

The examples use the @girs/* NPM packages for TypeScript definitions. These are pre-generated type definitions that you can also generate yourself using the ts-for-gir CLI with the --package option. For more information on CLI options, see the CLI documentation.

Quality Assurance and Testing

All examples in this directory are part of our Continuous Integration (CI) pipeline. They are:

  • Built during CI runs
  • Validated for TypeScript type correctness
  • Many are even executed as part of automated tests

This process ensures that our generated TypeScript definitions correctly match the GObject introspection data and work as expected in real applications. When issues with the type definitions are discovered, we often create or adapt examples to cover those edge cases and prevent regressions.

If you encounter a situation where the generated types don't work correctly, we encourage you to:

  1. Create a minimal example demonstrating the issue
  2. Submit it as a pull request
  3. Or open an issue with details about the problem

This collaborative approach helps us improve the quality of the type definitions for everyone.

Available Examples

GTK 4 Examples

ExampleDescriptionBundler
GTK 4 Template (Blueprint + Vite)Blueprint UI files with Vite plugin for direct import supportVite
GTK 4 Template (Vite)Modern UI with Vite for template and CSS loadingVite
GTK 4 Template (esbuild)Template-based UI using esbuild for asset loadingesbuild
GTK 4 Template (TSC)Pure TypeScript compilation with runtime asset loadingTSC
GTK 4 ApplicationBasic GTK 4 application structureesbuild
GTK 4 ListStoreData management with TreeView and ListStoreesbuild
GTK 4 Custom WidgetCreating custom widgets and virtual functionsesbuild
GTK 4 GettextInternationalization with gettextesbuild
GTK 4 Signal HelpersSignal connection utilities and patternsesbuild
GTK 4 Signal InterfacesAdvanced signal handling and interface patternsesbuild

GTK 3 Examples

ExampleDescriptionBundler
GTK 3 BrowserWeb browser using WebKitWebpack
GTK 3 BuilderUI design with Glade/BuilderWebpack
GTK 3 CalculatorSimple calculator applicationesbuild
GTK 3 ClutterGraphics with Clutter integrationTSC
GTK 3 EditorText editor applicationParcel
GTK 3 Hello WorldMinimal GTK 3 applicationRollup
GTK 3 Hello World 2Alternative GTK 3 hello worldesbuild
GTK 3 TemplateGTK 3 template-based UIesbuild
GTK 3 WebKitWebKit integration exampleesbuild

Libadwaita Examples

ExampleDescriptionBundler
Adwaita Hello WorldModern GNOME UI with LibadwaitaVite

Gio and GLib Examples

ExampleDescriptionBundler
Gio Action EntriesGAction and menu integrationesbuild
Gio Async OperationsAsynchronous file and network operationsesbuild
Gio CatFile system operations with Gioesbuild
Gio DBusDBus client/server communicationesbuild
Gio IterationFile and directory iterationesbuild
Gio List ModelVirtual interface implementation exampleesbuild
GLib Spawn CommandProcess spawning and command executionesbuild
GLib TypesGLib data types and utilitiesesbuild
GLib VariantGVariant serialization and handlingesbuild
GObject Param SpecGObject property specificationsesbuild

Database Examples

ExampleDescriptionBundler
GOM SQLite ORMSQLite ORM with GOM (insert, find, update, migrate)esbuild
GDA SQLiteSQLite with libgda (raw SQL, SqlBuilder, DataModel)esbuild

Cairo and Graphics Examples

ExampleDescriptionBundler
Cairo Drawing2D graphics with CairoTSC
Clutter Graphics3D graphics with ClutterTSC

Network and Communication Examples

ExampleDescriptionBundler
Soup HTTPHTTP client/server with Soup 3esbuild
Soup WebSocketWebSocket communication with Soup 3esbuild

Utility and System Examples

ExampleDescriptionBundler
Console ApplicationCommand-line application exampleTSC
Package TSCPackage structure with TypeScriptTSC
Run AsyncAsynchronous execution patternsesbuild
ST Layout ManagerSt layout management utilitiesesbuild
TimersTimer and scheduling examplesesbuild

Dependency Injection Examples

ExampleDescriptionDI LibraryBundler
DI with NeedleGObject + automatic dependency resolutionNeedle DIesbuild
DI with WiseType-safe dependency injection with interfacesdi-wiseesbuild
DI with TSyringeTraditional DI with parameter decoratorsTSyringeesbuild

Virtual Interface Examples

ExampleDescriptionBundler
Virtual Interface TestComprehensive virtual interface examplesesbuild

How to Run Examples

For most examples, you can use:

cd examples/<example-directory>
gjsify install
gjsify run start  # This will build and run the example

Some examples like the DBus and HTTP examples have separate client and server parts:

# For DBus example
cd examples/gio-2-dbus
gjsify install
gjsify run start:server  # In one terminal
gjsify run start:client  # In another terminal

# For HTTP example
cd examples/soup-3-http
gjsify install
gjsify run start:server  # In one terminal
gjsify run start:client  # In another terminal

TypeScript Configuration

Each example includes a tsconfig.json file that shows how to configure TypeScript for GJS applications. This typically includes:

  • Setting the module system to ESNext
  • Configuring the appropriate lib and types
  • Including the necessary GIR type declarations

For example:

{
  "compilerOptions": {   
    "lib": ["ESNext"],
    "types": ["@girs/gjs", "@girs/gjs/dom", "@girs/gio-2.0", "@girs/glib-2.0", "@girs/gtk-4.0", "@girs/adw-1"],
    "target": "ESNext",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "strict": true,
    "outDir": "dist"
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

Using with Different Type Generation Methods

The examples can be used with different methods of type generation:

  1. Pre-generated NPM packages: Most examples use @girs/* packages from npm (e.g., @girs/gtk-4.0)
  2. Local generation with CLI: You can generate types directly using the CLI:
    npx @ts-for-gir/cli generate Gtk-4.0 --outdir ./@types
    

For more information on CLI options and type generation, see the CLI documentation.

Contributing Examples

Feel free to contribute new examples that showcase:

  • Different libraries from the GObject ecosystem
  • Different bundlers or build systems
  • Interesting UI patterns or application architectures
  • Advanced TypeScript features with GJS

If you discover cases where the generated type definitions don't work correctly, creating a minimal example that demonstrates the issue can be extremely helpful for us to fix it.

Example Previews

Here are visual previews of the examples:

GTK 4 Examples

GTK 4 Template (Blueprint + Vite)

GTK 4 Template Blueprint Vite

GTK 4 Template (Vite)

GTK 4 Template Vite

GTK 4 Template (esbuild)

GTK 4 Template esbuild

GTK 4 Template (TSC)

GTK 4 Template TSC

GTK 4 ListStore

GTK 4 ListStore

GTK 4 Custom Widget

GTK 4 Custom Widget

Cairo Examples

Cairo Drawing

Cairo Drawing

GTK 3 Examples

GTK 3 Browser

GTK 3 Browser

GTK 3 Builder

GTK 3 Builder

GTK 3 Calculator

GTK 3 Calculator

GTK 3 Clutter

GTK 3 Clutter

GTK 3 Editor

GTK 3 Editor

GTK 3 Hello World

GTK 3 Hello World

Libadwaita Examples

Adwaita Hello World

Adwaita Hello World