Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Rouneq opened this issue Jun 23, 2022 · 0 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@Rouneq
Copy link

Rouneq commented Jun 23, 2022

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.

@sumneko sumneko added this to the 3.4.0 milestone Jun 23, 2022
@sumneko sumneko added the bug Something isn't working label Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants