Skip to content

get_node() function should have generics in TypeScript #126

Open
@Terria-K

Description

@Terria-K

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

private Sprite sprite;

public override void _Ready() 
{
     sprite = GetNode<Sprite>("path/to/sprite");
}

But in typescript, we are not allowed to write <T> or generics to get_node() like in C#. Instead, we use as to convert the Node into other class that is inherited to Node.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions