Skip to content

Indexing a table by an enum #2402

Answered by carsakiller
vallode asked this question in Q&A
Discussion options

You must be logged in to vote

The enum is expected to be used instead of 0:

---@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 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 because building_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.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by vallode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants