0 votes

In one of my classes, I've created a function that returns self.
Does anybody know of a way define the return type with static typing?
I know this can be done if using class_name, but I want to keep the global namespace clean.

# MyClass.gd
extends Node

func self_returning_func(): # -> MyClass
    return self
asked Feb 18 in Engine by zhyrin (26 points)

There are issues open about it:

It will likely get worked on soon, vnen is now full time on GDScript.

1 Answer

+1 vote

I think, if you are not using class_name, Godot will consider this object as Node. Or anything you extends from.

"MyClass" actually does not exist before declaring it as class_name or class.

answered Feb 18 by Ajver (20 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.