-
-
Notifications
You must be signed in to change notification settings - Fork 305
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
[Feature request] generics in overload #723
Comments
Interesting... Aside of the EmmyLua annotation, how do you achieve overloading in Lua? 👀 |
@Miqueas Basic overloading is achieved by checking the types of function arguments and returning a value according to the data obtained: ---@overload fun(v1:number, v2:number):number
---@overload fun(v1:string):string
local function demo(...)
local args = {...}
if #args == 2
and type(args[1]) == 'number'
and type(args[2]) == 'number' then
return args[1] + args[2]
elseif #args == 1
and type(args[1]) == 'string' then
return args[1]:upper()
end
error('wrong arguments', 2)
end
assert(demo(2, 2) == 4)
assert(demo('hello') == 'HELLO') A more complex version is demonstrated here. |
@lua-rocks awesome, thanks! |
Just discovered this problem as well. Looking forward to being able to use both of these together. I don't think any additional annotation should be required. Overload just needs to accept the already specified generic annotation. |
Just want to add my +1 to this as well. Just ran into this issue. Would be great to have. |
As far as I know, it is not possible to use
@generic
in@overload
?I have a table
Object
that has a__call
metamethod, so class Object can be used as function:Object()
==Object:new()
... And I want to overload class Object with function
new()
. This function use generics 🤯The text was updated successfully, but these errors were encountered: