On latest static GDScript typing, there are some virtual functions that return Variant
, and there's no way to replicate that in GDScript. What comes to mind is Object._get
function for example. There's no way to say func _get(property: String) -> Variant
in GDScript, "best" implementation so far is to ignore return value: func _get(property: String)
.
We need a mechanism to return not just Object & built-in types but Variant
as well or maybe there are other options out there too?
Ignoring the return type is effectively the same as returning Variant.
Yeah but that doesn't fix the problem. What do you do with the other virtual methods that expect Variant
as parameter? like _set
, I mean sure, you can do the same, define it with no typing hints: func _set(property: String, val) -> void
, but I guess I prefer having a generic type hint like Variant
exposed to make it explicit
Variant
is also present on the class reference as a core type, but is not exposed to GDScript.
I like the idea of a generic type hint too (similar to TypeScript's any
type, whose usage can be enforced using the noImplicitAny
flag). In a static typing-first workflow, this makes sure every usage of dynamic typing is carefully considered.
We could then have a GDScript warning (disabled by default) that would be emitted whenever type hints aren't specified somewhere.
Closing in favor of https://github.com/godotengine/godot-proposals/issues/605, as feature proposals are now tracked on the Godot proposals repository.
For anyone stumbling upon this issue from a web search, this is now supported in master
since the new GDScript was merged:
Most helpful comment
I like the idea of a generic type hint too (similar to TypeScript's
any
type, whose usage can be enforced using thenoImplicitAny
flag). In a static typing-first workflow, this makes sure every usage of dynamic typing is carefully considered.We could then have a GDScript warning (disabled by default) that would be emitted whenever type hints aren't specified somewhere.