Skip to content

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