Indexing a table by an enum #2402
-
Hello, thank you the time spent developing the lua LSP. I have a quick question regarding table types. In the example below I have an enum, and a table that is accessed with those enum values only, but I cannot figure out a way for the LSP to accurately display this information. ---@enum building_id
local building_id = {
ANY = -1,
ONE = 0,
TWO = 1,
}
---@type { [building_id]: { name: string } }
local building_attributes = {}
Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The enum is expected to be used instead of ---@enum building_id
local building_id = {
ANY = -1,
ONE = 0,
TWO = 1,
}
---@type { [building_id]: { name: string } }
local building_attributes = {}
local anyName = building_attributes[building_id.ANY].name While This may just not be supported right now. You can convert this discussion to an issue and we can see. |
Beta Was this translation helpful? Give feedback.
The enum is expected to be used instead of
0
:While
building_id.ANY
and-1
are equal, I think it does make sense to expect the enum to be used (that is its purpose)... but I can also see how this could be annoying becausebuilding_id.ANY
is equal to-1
and they could be used interchangeably.This may just not be supported right now. You can convert this discussion to an issue and we can see.