@girs/gjs

中文文档
5.6.0发布于 2026/10/28MITTypeScriptES Module构建来源已验证近 30 天下载 72.1万

GJS TypeScript type definitions for Gjs

原始使用文档
文档目录8 节
  1. Install
  2. Usage
  3. Global types
  4. Global DOM types
  5. Ambient Modules
  6. GIR modules
  7. Bundle
  8. Other packages

Gjs

version downloads/week

GJS TypeScript type definitions for Gjs using ts-for-gir v5.6.0.

GJS is GNOME's JavaScript runtime. With these type definitions your editor knows the GTK API: it type-checks calls, completes method names, and shows the upstream C documentation inline.

Install

Install the type definitions with npm:

npm install @girs/gjs

Usage

Import it like any other module:

import Gjs from '@girs/gjs';

For CommonJS:

const Gjs = require('@girs/gjs');

Global types

After the import, the global types of GJS are also available:

import '@girs/gjs';

print('Hello World from print');

const ByteArray = imports.byteArray;

// And so on...

Global DOM types

Some types that conflict with the DOM are outsourced to allow frameworks like Gjsify to rebuild the DOM API without causing type conflicts. Import them explicitly:

import '@girs/gjs/dom';

console.log('Hello World from console');

const encoder = new TextEncoder();
const encoded = encoder.encode('𝓽𝓮𝔁𝓽');

setTimeout(() => {
  // ...
}, 1000);

// And so on...

These collide with the DOM types. Exclude the DOM lib in your tsconfig.json or jsconfig.json, or set noLib.

Ambient Modules

GJS's built-in ambient modules are importable too. For this you need to include the @girs/gjs or @girs/gjs/ambient in your tsconfig or entry point Typescript file:

index.ts:

import '@girs/gjs'

tsconfig.json:

{
  "compilerOptions": {
    ...
  },
  "include": ["@girs/gjs"],
  ...
}

gettext, system and cairo now resolve as ESM imports, with types:

import gettext from 'gettext';
import system from 'system';
import cairo from 'cairo';

GIR modules

If you want to have types for GObject Introspection modules, you have to add them to your dependencies and import them as well, see the description of these modules, e.g. gtk-4.0, gio-2.0, adw-1 and much more.

These types will then be available to you:

import '@girs/gjs'
import '@girs/gjs/dom'
import '@girs/gio-2.0'
import '@girs/gtk-4.0'
import '@girs/adw-1'

import Gio from 'gi://Gio?version=2.0';
import Gtk from 'gi://Gtk?version=4.0';
import Adwaita from 'gi://adw?version=1';

const button = new Gtk.Button();

// ...

Bundle

Most projects want a bundler. esbuild is the smallest thing that works; the examples directory has setups for several others.

Other packages

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

版本与发布记录

@girs/gjs 共发布 94 个版本,首次发布于 2023/03/24;过去 12 个月发布了 43 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.6.0latest2026/10/2819 天前
5.5.02026/10/021 个月前
5.4.02026/09/211 个月前
5.3.02026/09/191 个月前
5.2.02026/09/152 个月前
5.1.02026/09/152 个月前

其他发布通道:next → 4.0.0-beta.5。

关于 @girs/gjs 的常见问题

@girs/gjs 是什么?

GJS TypeScript type definitions for Gjs

如何安装 @girs/gjs?

在项目目录运行 npm install @girs/gjs,或使用 pnpm add / yarn add / bun add。

@girs/gjs 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@girs/gjs 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@girs/gjs 可以商用吗?

@girs/gjs 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@girs/gjs 的下载量有多少?

根据 npm 官方下载统计,@girs/gjs 在 2026/10/17 – 2026/11/15 这 30 天内被下载 720,762 次,日均约 24,025 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@girs/gjs 还在维护吗?

最新版本 5.6.0 发布于 2026/10/28(19 天前);至今共发布 94 个版本,其中过去 12 个月发布了 43 个;首次发布于 2023/03/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。