How to define parameters for instantiating a class with annotations? #2213
Unanswered
gagehenderson
asked this question in
Q&A
Replies: 1 comment
-
You can document a ---@class myClass
---@overload fun(name: string): myClass
local myClass = {}
---@param name string
function myClass.new(name)
--...
end |
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
Uh oh!
There was an error while loading. Please reload this page.
-
Last month I started heavily using the annotations feature and it's been extremely helpful for me as my codebase gets larger and larger for my project.
However, I am using some OOP throughout my project and I haven't figured out how to define what parameters need to be passed to classes when creating instances of them.
Quick example:
This doesn't seem to actually provide any context when instantiating my class somewhere else. I was wondering if there's currently any way to do this - Or even if there's a workaround to enable this, I'm willing to refactor some stuff just to make this work.
Also, in practice I tend to actually use the
__call
metamethod rather than calling any sort of:new
or:init
method.I apologize if this is a question that has already been answered, this seems like something a lot of people would run into but I haven't found any exact answers.
Beta Was this translation helpful? Give feedback.
All reactions