Using static typing of self type in a custom class

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By zhyrin

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
:bust_in_silhouette: Reply From: Ajver

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.