godotjs / godotjs/javascript

get_node() function should have generics in TypeScript

Aperta
#126 0 commenti 2 reazioni 0 assegnatari Vedi su GitHub
enhancement
Lingua principale
C++
Stelle
1.1k
Fork
80
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.