Skip to content

Commit 3d66a57

Browse files
feat: Improved support for statically typed optional nodes
1 parent 5bc325e commit 3d66a57

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@godot-js/editor": patch
3+
---
4+
5+
**Types:** Improved support for statically typed optional nodes.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ const TypeMutations: Record<string, TypeMutation> = {
422422
get_children: mutate_return_type('GArray<NodePathMapChild<Map>>'),
423423
get_node: ["get_node<Path extends StaticNodePath<Map>, Default = never>(path: Path): ResolveNodePath<Map, Path, Default>"],
424424
get_node_or_null: [
425-
"get_node_or_null<Path extends StaticNodePath<Map>, Default = never>(path: Path): null | ResolveNodePath<Map, Path, Default>",
425+
"get_node_or_null<Path extends StaticNodePath<Map, undefined | Node>, Default = null>(path: Path): null | ResolveNodePath<Map, Path, Default, undefined | Node>",
426426
"get_node_or_null(path: NodePath | string): null | Node",
427427
],
428428
move_child: mutate_parameter_type(names.get_parameter('child_node'), 'NodePathMapChild<Map>'),

scripts/typings/godot.mix.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,10 @@ declare module "godot" {
156156
DummyKey extends any
157157
? (
158158
Path extends keyof Map
159-
? Map[Path] extends Permitted
160-
? Map[Path]
159+
? [Map[Path]] extends [Permitted]
160+
? [undefined] extends [Map[Path]]
161+
? null | Exclude<Map[Path], undefined>
162+
: Map[Path]
161163
: Default
162164
: Path extends `${infer Key extends Exclude<keyof Map, DefaultKey> & string}/${infer SubPath}`
163165
? Map[Key] extends PathMappable<DummyKey, infer ChildMap>
@@ -177,9 +179,9 @@ declare module "godot" {
177179
>;
178180

179181
type NodePathMap = PathMap<Node>;
180-
type StaticNodePath<Map extends NodePathMap> = StaticPath<Map, Node, never, typeof __PathMappableDummyKeys.Node>;
181-
type ResolveNodePath<Map extends NodePathMap, Path extends string, Default = never> =
182-
ResolvePath<Map, Path, Default, Node, never, typeof __PathMappableDummyKeys.Node>;
182+
type StaticNodePath<Map extends NodePathMap, Permitted = Node> = StaticPath<Map, Permitted, never, typeof __PathMappableDummyKeys.Node>;
183+
type ResolveNodePath<Map extends NodePathMap, Path extends string, Default = never, Permitted = Node> =
184+
ResolvePath<Map, Path, Default, Permitted, never, typeof __PathMappableDummyKeys.Node>;
183185
type ResolveNodePathMap<Map extends NodePathMap, Path extends string, Default = never> = Path extends keyof Map
184186
? Map[Path] extends Node<infer ChildMap>
185187
? ChildMap

0 commit comments

Comments
 (0)