Skip to content

Enhancement to allow typing an enum alias (and inheriting from the type) #1229

@Rouneq

Description

@Rouneq

Currently, alias only takes a name along with values (using the expanded form of alias for example purposes)

---@alias areaType
---| 'TOP'
---| 'BAG

---@param area? areaType
StoreItem = function (area)
    if (area:lower() == 'top') then
        print('this is a top area')
    end
end

The problem comes in that if I want to do anything with those values such as normal string operations (e.g., area:lower()), the editor reports that operation as an undefined field.

UndefinedFieldLower

I can add string to the alias to eliminate this error.

---@alias areaType string
---| 'TOP'
---| 'BAG

However, string now shows up in the function signature.

areaTypeAnnotation

I also tried adding ---@type string in front of the alias, but this wasn't recognized.

An enhancement to allow typing the alias or automatically recognizing a list of string values and bringing in the string operations accordingly would address this. I'd prefer the explicit typing as this would open the door to creating enums of other types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions