Parameterised Types and Type Hinting a Custom Class/Resource

Godot Version

4.4.1.stable

Question

I was wondering if there is any way to parameterise property types and subsequently type hint a custom class, much the same way you can type hint an Array for example. Below is hypothetically what it might look like:

var array_of_int: Array[int]

class Foo(T):
	var bar: T

var foo_of_int: Foo[int]

For the record, I had Python’s Generics and TypeVar in mind. From what I’ve seen, Godot’s Variant isn’t up to the task? Thanks!

No, it’s not possible. There are multiple proposals open for that like Add generic parameters to allow strongly typing for collections · Issue #1207 · godotengine/godot-proposals · GitHub but I doubt they will be added any time soon.

Thanks for the info. I’ll keep an eye those issues.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.