-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Statically typed Callable #10807
Comments
This is related to
The team on GDScript occasionally talks about this kind of thing, but it can't come any time soon due to severe changes being required to the typing system and the GDScript parser, first. |
Yes, I agree the implementation of "generics" as we have them seem to be a hack. I hope that the generics get a more unified system that makes it trivial to create generic classes, methods, and variables though, it would make life a lot simpler in these kinds of scenarios. |
Describe the project you are working on
Any project that uses lambda functions heavily
Describe the problem or limitation you are having in your project
Callables have no defined type of parameter list
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add a type field to Callable, similar to Array and Dictionary
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
When defining a Callable, you can add as many type parameters as you want. These would all be valid:
Lambda functions will not need type hints if types are declared in the variable or parameter, making them more concise but still type safe:
Since actual class and method generics aren't supported (the way it's implemented in other languages), things like Array methods (map, reduce, filter) still won't work correctly.
Callable would also have methods for getting the types, like Array does:
If this enhancement will not be used often, can it be worked around with a few lines of script?
It requires casting, which I think is undesirable
Is there a reason why this should be core and not an add-on in the asset library?
GDScript is core
The text was updated successfully, but these errors were encountered: