You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This Lua LSP could benefit from a new @constructor tag, which would be used when defining classes, especially with libraries. Currently, we have to do something like this:
---@classmyCls---@overloadfun(a: integer, b: integer): myClslocalmyCls=class"myCls"---@paramainteger---@parambintegerfunctionmyCls:__init(a, b)
self.a=aself.b=bendlocalinstance=myCls(10, 20)
print(instance)
As you can see, we need to create an overload for the variable, which makes the typing process quite repetitive. To address this, we could introduce a new @constructor tag that would automatically handle this:
---@classmyClslocalmyCls=class"myCls" -- No need for an overload anymore.-- Defining this method as the constructor:---@constructor---@paramainteger---@parambintegerfunctionmyCls:__init(a, b)
self.a=aself.b=bendlocalinstance=myCls(10, 20) -- Type checking would work correctly and show the constructor parameters.print(instance)
This approach would make the code cleaner and more intuitive, reducing the need for repetitive annotations and improving the overall developer experience.
The text was updated successfully, but these errors were encountered:
ErickProgramer
changed the title
@constructor tag
Proposal: Add @constructor Tag for Class Constructors in Lua LSP
Feb 7, 2025
This Lua LSP could benefit from a new @constructor tag, which would be used when defining classes, especially with libraries. Currently, we have to do something like this:
As you can see, we need to create an overload for the variable, which makes the typing process quite repetitive. To address this, we could introduce a new @constructor tag that would automatically handle this:
This approach would make the code cleaner and more intuitive, reducing the need for repetitive annotations and improving the overall developer experience.
The text was updated successfully, but these errors were encountered: