godotjs / godotjs/javascript

get_node() function should have generics in TypeScript

Open
#126 0 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
C++
Stars
1.1k
Forks
80
PR merge metrics
No merged PRs in 30d

Description

In C#, we are able to use the simplest and nice `` as a shortcut and cleaner version of `(T)` or `as` to convert the Node into other class that is inherited to Node:
```csharp
private Sprite sprite;

public override void _Ready()
{
sprite = GetNode("path/to/sprite");
}
```
But in typescript, we are not allowed to write `` or generics to `get_node()` like in C#. Instead, we use `as` to convert the Node into other class that is inherited to Node.
```typescript
private sprite: godot.Sprite;

public override _ready(): void {
this.sprite = this.get_node('path/to/sprite') as godot.Sprite;
}
```
I'd make a workaround by editing the godot.d.ts but it would be nice if it's built-in to the module.

Contributor guide

Open the contributing guide

Research direction

Start in godot.d.ts and locate the get_node() declaration described in the issue. Update that declaration so callers can provide a TypeScript generic for the returned Node type, then verify that the example no longer needs an as cast.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
game-dev
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.