More robust function type syntax
Benjamin-Dobell opened this issue · comments
Right now we've two ways to type functions, and a third way to type a callable that mostly behaves like a function
- Short form
- Long form
- Callable shape
All forms have limitations. There is no solution that currently offers all the features we need.
1. Short form
fun<T>(param1: T): void
Feature | Supported |
---|---|
Overloads | ❎ |
Documentation | ❎ |
Usable without function definition | ☑️ |
Usable without explicit type name | ☑️ |
2. Long form
--- Function description
---@generic T
---@param param1 T @Param description
---@overload fun(): void
---@return void
Feature | Supported |
---|---|
Overloads | ☑️ |
Documentation | ❓[1] |
Usable without function definition | ❎ |
Usable without explicit type name | ☑️ |
[1] Because overloads use short form, overloads cannot be documented.
3. Callable shape
---@shape Callable<T>
---@overload fun(param1: T): void
---@overload fun(): void
Feature | Supported |
---|---|
Overloads | ☑️ |
Documentation | ❎ |
Usable without function definition | ☑️ |
Usable without explicit type name | ❎ |
Solution?
I don't have a solution as of yet.
Ideally we want a syntax that ticks all boxes. No doubt the solution is going to have to more closely resemble long form, but with overload support, and the ability to be attached to variable declarations local var
etc.
The reason it's desirable for the syntax to support variable declarations is to support forward declaration of functions, without having to repeat any part of the type definition upon assignment.