Replies: 2 comments 3 replies
-
using [] could lead to confusion with arrays var whatever: Callable((int, int) -> int) |
Beta Was this translation helpful? Give feedback.
3 replies
-
The problem is that GDScript supports dynamic typing, so in general this requires runtime checks, similar to how typed arrays are implemented. Also, this would affect not only GDScript, but also the core. Godot doesn't have a unified type system, if you expect something like: class Array[T]
func filter(method: Callable[[T], bool]) -> Array[T]
func map[TOther](method: Callable[[T], TOther]) -> Array[TOther]
func reduce[TAccum](method: Callable[[TAccum, T], TAccum], accum: TAccum|Nil = null) -> TAccum |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think most people agree that type hints can help to reduce runtime errors. GDScript type hints can uncover many errors early, before even running the code. Callables are also a useful feature, but sadly, they lack type hints.
I think it would be great, if Callables could have type annotations. As GDScript is inspired by Python, I would consider a syntax similar to Python:
This syntax could also be used in function parameters:
A annotation directly on the function definition might also make sense:
Beta Was this translation helpful? Give feedback.
All reactions