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
{{ message }}
Repository navigation
Local reference to enum defined in an object from a different file, same workspace #3328
Simply make a local reference to an enum defined in a table, try to use it.
Additional Notes
I want to share an enum across lua files and have a reference on it so that I can type Color.Blue instead of module.Color.Blue. Lua allows me to have a local reference, doing local Color = module.Color compile and works just fine, but the diagnostic is not happy, marking the local reference as ---@type Module.Color doesn't seem enough.
I feel like I might be doing this wrong, is there a syntax to achieve what I am trying to do? I cannot put the enum Color in global space, I have to put it in the module object, so that it does not clash with other modules.
Basically, skip using @enum and make up a custom enum declaration. However this lose the enum validation, since now using ---@param Module.Color allows for any string to be passed to the function.
Please let me know if this can be achieved using @enum with some syntax I could not figure out.
localmodule=require"module"-- the server already know the type of `module.Color`localColor=module.Colorprint(Color.Black)
print(Color.NoSuchColor) --<< warning: undefined field
Sorry I forgot to mention that there is no return module nor require "module" in my Lua environment (this is WoW Lua 5.1 environment), and the way the "module" object is passed around is by providing it as an argument when they load the lua file, we get the "module" by fetching it with local moduleName, module = ... at the top of each lua file of the project.
Would this environment cause issues with how the Lua language server process types across units?
But in any case, that comment you posted indeed contained the solution to my issue! And I don't even need the ---@type anymore in file2.lua, which is even better. ❤️ thank you very much!
Here is the full working syntax if anyone ever search for this again (the key was really the ---@class and .* combinaison) :
Activity
erunehtar commentedon Jan 9, 2026
I was able to workaround it by doing:
file1.lua
file2.lua
Basically, skip using
@enumand make up a custom enum declaration. However this lose the enum validation, since now using---@param Module.Colorallows for any string to be passed to the function.Please let me know if this can be achieved using
@enumwith some syntax I could not figure out.tomlau10 commentedon Jan 10, 2026
I believe you misused the
@enum.please see #3151 (comment)
And if your
module.luaalready return that module table, you actually don't need@typeat all 🤔erunehtar commentedon Jan 10, 2026
Sorry I forgot to mention that there is no
return modulenorrequire "module"in my Lua environment (this is WoW Lua 5.1 environment), and the way the "module" object is passed around is by providing it as an argument when they load the lua file, we get the "module" by fetching it withlocal moduleName, module = ...at the top of each lua file of the project.Would this environment cause issues with how the Lua language server process types across units?
But in any case, that comment you posted indeed contained the solution to my issue! And I don't even need the
---@typeanymore infile2.lua, which is even better. ❤️ thank you very much!Here is the full working syntax if anyone ever search for this again (the key was really the
---@classand.*combinaison) :file1.lua
file2.lua