lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Better support for varargs in functions in classes declared with @field

Open emmericp opened this issue 1 year ago • 0 comments

I ran into a minor problem with how vararg is handled in function declarations in an field annotation when the function declaration itself later explicitly lists the arguments.

---@class Handler
---@field ReceiveMsg fun(self: Handler, type: number, ...: string)
local handler = {}

function handler:ReceiveMsg(arg1, arg2, arg3, arg4)
 --- arg2 is inferred as string, but arg3 and arg4 are "any"
end

Why do I even have this mismatch between field and function declaration? The field annotation comes from a library and is an event handler -- the number of parameters depend on a lot of things, but for a given implementation you usually only care about a few that you explicitly declare.

emmericp avatar Mar 03 '24 14:03 emmericp