https://github.com/react-gjs/gjs-esm-types
https://github.com/react-gjs/gjs-esm-types
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/react-gjs/gjs-esm-types
- Owner: react-gjs
- License: mit
- Created: 2023-03-04T19:50:16.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-04T15:01:25.000Z (over 2 years ago)
- Last Synced: 2025-04-05T22:32:42.625Z (9 months ago)
- Language: JavaScript
- Size: 4.59 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
#### This package provides module declarations for some of the most common GJS gir modules (see [Gnome JavaScript](https://gjs.guide/about/)). With it you will get fully typed imports for the following modules:
- `gi://Atk?version=1.0`
- `gi://GLib?version=2.0`
- `gi://GModule?version=2.0`
- `gi://GObject?version=2.0`
- `gi://Gdk?version=3.0`
- `gi://Gdk?version=4.0`
- `gi://GdkPixbuf?version=2.0`
- `gi://Gio?version=2.0`
- `gi://Graphene?version=1.0`
- `gi://Gsk?version=4.0`
- `gi://Gtk?version=3.0`
- `gi://Gtk?version=4.0`
- `gi://HarfBuzz?version=0.0`
- `gi://Pango?version=1.0`
- `gi://PangoCairo?version=1.0`
- `gi://Soup?version=2.4`
- `gi://Soup?version=3.0`
- `gi://cairo?version=1.0`
- `gi://freetype2?version=2.0`
- `gi://xlib?version=2.0`
Additionally a module declaration for `system` module is included as well as some global functions and variables like `globalThis.print()`, `globalThis.imports`, `globalThis.pkg` etc.
# Use
1. Install this package via npm or yarn
2. Add this package to the tsconfig.json typeRoots:
```json tsconfig.json
{
"compilerOptions": {
"typeRoots": ["node_modules/gjs-esm-types", "node_modules/@types"]
}
}
```
3. `gi` imports should now be correctly typed:
```ts
import Gtk from "gi://Gtk?version=3.0";
const window = new Gtk.Window();
// Resolved Type - const window: Gtk.Window;
```
# Imports without version specifier
This package only provides module declarations for imports with a version specifier. If you want your imports to not include the version, add a `.d.ts` file in your project and define the module declarations in there, similarly to this:
### Example 1 - Gtk
```ts
declare module "gi://Gtk" {
import Gtk from "gi://Gtk?version=4.0";
export default Gtk;
}
```
### Example 2 - GLib
```ts
declare module "gi://GLib" {
import GLib from "gi://GLib?version=2.0";
export default GLib;
}
```
### Example 3 - Soup
```ts
declare module "gi://Soup" {
import Soup from "gi://Soup?version=2.4";
export default Soup;
}
```