@ts-for-gir/generator-typescript 4.0.0-beta.42 → 4.0.0-beta.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-for-gir/generator-typescript",
3
- "version": "4.0.0-beta.42",
3
+ "version": "4.0.0-beta.44",
4
4
  "description": "TypeScript type definition generator for ts-for-gir",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
@@ -31,17 +31,17 @@
31
31
  "generator"
32
32
  ],
33
33
  "devDependencies": {
34
- "@ts-for-gir/tsconfig": "^4.0.0-beta.42",
34
+ "@ts-for-gir/tsconfig": "^4.0.0-beta.44",
35
35
  "@types/ejs": "^3.1.5",
36
36
  "@types/node": "^24.12.0",
37
37
  "@types/xml2js": "^0.4.14",
38
- "typescript": "^5.9.3"
38
+ "typescript": "^6.0.2"
39
39
  },
40
40
  "dependencies": {
41
- "@gi.ts/parser": "^4.0.0-beta.42",
42
- "@ts-for-gir/generator-base": "^4.0.0-beta.42",
43
- "@ts-for-gir/lib": "^4.0.0-beta.42",
44
- "@ts-for-gir/templates": "^4.0.0-beta.42",
41
+ "@gi.ts/parser": "^4.0.0-beta.44",
42
+ "@ts-for-gir/generator-base": "^4.0.0-beta.44",
43
+ "@ts-for-gir/lib": "^4.0.0-beta.44",
44
+ "@ts-for-gir/templates": "^4.0.0-beta.44",
45
45
  "ejs": "^5.0.1",
46
46
  "xml2js": "^0.6.2"
47
47
  }
@@ -107,8 +107,6 @@ export class SignalGenerator {
107
107
  const allSignals = girClass.getAllSignals();
108
108
 
109
109
  allSignals.forEach((signalInfo) => {
110
- const signalKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(signalInfo.name) ? signalInfo.name : `"${signalInfo.name}"`;
111
-
112
110
  let cbType: string;
113
111
 
114
112
  if (signalInfo.isNotifySignal) {
@@ -132,6 +130,14 @@ export class SignalGenerator {
132
130
  cbType = `(${paramTypes.join(", ")}) => ${returnTypeStr}`;
133
131
  }
134
132
 
133
+ // Template literal catch-all signals use index signature syntax
134
+ if (signalInfo.isTemplateLiteral) {
135
+ def.push(`${indent} [key: \`${signalInfo.name}\`]: ${cbType};`);
136
+ return;
137
+ }
138
+
139
+ const signalKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(signalInfo.name) ? signalInfo.name : `"${signalInfo.name}"`;
140
+
135
141
  // Add signal doc comment with @signal tag and signal-specific modifier tags
136
142
  if (!signalInfo.isNotifySignal && signalInfo.signal) {
137
143
  const signalTags = [
@@ -55,6 +55,7 @@ import {
55
55
  type TsDocTag,
56
56
  TypeConflict,
57
57
  type TypeExpression,
58
+ TypeIdentifier,
58
59
  transformGirDocTagTextWithContext,
59
60
  transformGirDocText,
60
61
  } from "@ts-for-gir/lib";
@@ -402,14 +403,16 @@ export class ModuleGenerator extends FormatGenerator<string[]> {
402
403
 
403
404
  clazz.superType = GLibError.getType();
404
405
 
405
- // Manually construct a GLib.Error constructor.
406
+ // GJS GError constructor expects one object: { message: string, code: number }
407
+ // The domain is automatically derived from the error enum type.
408
+ // See: gjs/gi/gerror.cpp ErrorInstance::constructor_impl
406
409
  clazz.mainConstructor = new IntrospectedConstructor({
407
410
  name: "new",
408
411
  parent: clazz,
409
412
  parameters: [
410
413
  new IntrospectedFunctionParameter({
411
414
  name: "options",
412
- type: NativeType.of("{ message: string, code: number}"),
415
+ type: NativeType.of("{ message: string, code: number }"),
413
416
  direction: GirDirection.In,
414
417
  }),
415
418
  ],
@@ -515,6 +518,13 @@ export class ModuleGenerator extends FormatGenerator<string[]> {
515
518
  const Type = type.resolve(this.namespace, this.options).rootPrint(this.namespace, this.options) || "any";
516
519
 
517
520
  if (construct) {
521
+ // If the property type is GType, use GTypeInput to also accept class constructors
522
+ // with $gtype (e.g., passing a class to Gio.ListStore's item_type property)
523
+ const unwrapped = type.deepUnwrap();
524
+ if (unwrapped instanceof TypeIdentifier && unwrapped.is("GObject", "GType")) {
525
+ const gtypeNamespace = this.namespace.namespace === "GObject" ? "" : "GObject.";
526
+ return [`${name}: ${gtypeNamespace}GTypeInput;`];
527
+ }
518
528
  return [`${name}: ${Type};`];
519
529
  }
520
530
 
@@ -1272,6 +1282,7 @@ export class ModuleGenerator extends FormatGenerator<string[]> {
1272
1282
  else if (girClass.mainConstructor instanceof IntrospectedConstructor)
1273
1283
  def.push(...this.generateConstructor(girClass.mainConstructor));
1274
1284
  else if (
1285
+ (girClass.namespace.namespace === "GObject" && girClass.name === "Object") ||
1275
1286
  girClass.someParent((p: IntrospectedBaseClass) => p.namespace.namespace === "GObject" && p.name === "Object")
1276
1287
  )
1277
1288
  def.push(`\nconstructor(properties?: Partial<${girClass.name}.ConstructorProps>, ...args: any[]);\n`);