Skip to content

Commit 0c2c197

Browse files
fix: GDictionary absent values are returned as null, not undefined
1 parent 3f11955 commit 0c2c197

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

scripts/jsb.editor/src/jsb.editor.codegen.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ const TypeMutations: Record<string, TypeMutation> = {
383383
"proxy<Write extends boolean = false>(): Write extends true ? GDictionaryProxy<T> : GDictionaryReadProxy<T>",
384384
"",
385385
`${names.get_member("set_keyed")}<K extends keyof T>(key: K, value: T[K]): void`,
386-
`${names.get_member("get_keyed")}<K extends keyof T>(key: K): T[K]`,
386+
`${names.get_member("get_keyed")}<K extends keyof T>(key: K): UndefinedToNull<T[K]>`,
387387
],
388388
property_overrides: {
389389
assign: mutate_parameter_type("dictionary", "T"),
@@ -394,10 +394,10 @@ const TypeMutations: Record<string, TypeMutation> = {
394394
find_key: chain_mutators(mutate_parameter_type("value", "T[keyof T]"), mutate_return_type("keyof T")), // This can be typed more accurately with a mapped type, but it seems excessive.
395395
erase: mutate_parameter_type("key", "keyof T"),
396396
keys: mutate_return_type("GArray<keyof T>"),
397-
values: mutate_return_type("GArray<T[keyof T]>"),
397+
values: mutate_return_type("GArray<UndefinedToNull<T[keyof T]>>"),
398398
duplicate: mutate_return_type("GDictionary<T>"),
399-
get: chain_mutators(mutate_parameter_type("key", "K"), mutate_return_type("T[K]"), mutate_template("K extends keyof T")),
400-
get_or_add: chain_mutators(mutate_parameter_type("key", "K"), mutate_parameter_type("default_", "T[K]"), mutate_template("K extends keyof T")),
399+
get: chain_mutators(mutate_parameter_type("key", "K"), mutate_return_type("UndefinedToNull<T[K]>"), mutate_template("K extends keyof T")),
400+
get_or_add: chain_mutators(mutate_parameter_type("key", "K"), mutate_return_type("UndefinedToNull<T[K]>"), mutate_parameter_type("default_", "T[K]"), mutate_template("K extends keyof T")),
401401
set: chain_mutators(mutate_parameter_type("key", "K"), mutate_parameter_type("value", "T[K]"), mutate_template("K extends keyof T")),
402402
}
403403
},

scripts/typings/godot.mix.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ declare module "godot" {
9999
type ExtractValueKeys<T, V> = { [K in keyof T]: T[K] extends V ? K : never }[keyof T];
100100
type IfAny<T, Y, N> = 0 extends (1 & T) ? Y : N;
101101

102+
type UndefinedToNull<T> = T extends undefined ? null : T;
103+
102104
/**
103105
* This namespace and the values within do not exist at runtime. They're declared here, for internal use only, as a
104106
* work-around for limitations of TypeScript's type system.

0 commit comments

Comments
 (0)