This example shows how ts-for-gir v4 can be used to generate and use TypeScript types for GJS using esbuild.
- Install the dependencies using
npm install
- Run
npm run generate
to generate the TypeScript types - Rerun
npm install
to register the new types - Run
npm run build
to build the TypeScript code using esbuild - Run
npm run start
to start the code with GJS (alternatively rungjs -m main.js
)
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 esbuild.js
file is a simple script that uses esbuild
to build the TypeScript code instead of using tsc
.
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 runsts-for-gir
CLI to generate the types for theAdw-1
package.build
: This script runsesbuild.js
to build the TypeScript code.start
: This script runsgjs
to start the code with GJS.
- ts-for-gir-local-tsc-example - Almost identical example, but uses tsc to build the TypeScript code