Skip to content

An example of how ts-for-gir can be used locally with self generated GIR types and the TypeScript compiler

Notifications You must be signed in to change notification settings

gjsify/ts-for-gir-local-tsc-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ts-for-gir local tsc example

This example shows how ts-for-gir v4 can be used to generate and use TypeScript types for GJS.

Another option is to install the types via NPM, but this example shows how to create the types yourself so that the library version of the created types matches your local ones

Hello World GJS Gtk/Adwaita application

How to use

  1. Install the dependencies using npm install
  2. Run npm run generate to generate the TypeScript types
  3. Rerun npm install to register the new types
  4. Run npm run build to build the TypeScript code
  5. Run npm run start to start the code with GJS (alternatively run gjs -m main.js)

How it works

The tsconfig.json file is configured to use the ESNext target and lib setting, which allows for the use of ES module syntax and async/await. The types array is set to ["@girs/gjs", "@girs/gio-2.0", "@girs/adw-1", "@girs/gtk-4.0"] to include the generated types.

The main.ts file uses the generated types to create a simple Hello World GJS Gtk/Adwaita application.

The package.json file is configured to add the generated types to the workspace, So that the types can be found by the TypeScript compiler:

  "workspaces": [
    "@types/*"
  ]

In addition, 3 NPM scripts are included:

  • generate: This script runs ts-for-gir CLI to generate the types for the Adw-1 package.
  • build: This script runs tsc to build the TypeScript code.
  • start: This script runs gjs to start the code with GJS.

Other examples

About

An example of how ts-for-gir can be used locally with self generated GIR types and the TypeScript compiler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published