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

feat: type narrow types with literal fields #2864

Merged
merged 1 commit into from
Sep 23, 2024

Conversation

lewis6991
Copy link
Contributor

@lewis6991 lewis6991 commented Sep 22, 2024

---@class A
---@field type 'a'

---@class B
---@field type 'b'

local obj --- @type A|B

if obj.type == 'a' then
    -- obj is narrowed to type A
end

Currently only narrows types defined with @class. I attempted to make this work for @alias (as in #704) but it got rather complicated.

It may be beneficial to cache the result of getNodeTypesWithLiteralField.

@lewis6991 lewis6991 marked this pull request as ready for review September 22, 2024 16:23
@sumneko sumneko merged commit 1831e60 into LuaLS:master Sep 23, 2024
11 checks passed
@sumneko
Copy link
Collaborator

sumneko commented Sep 23, 2024

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants