LuaLS / LuaLS/lua-language-server
Type narrowing for unioned classes
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Lua
- Star
- 4.4k
- Fork
- 442
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
I have a large number of classes that look something like this:
---@class Foo
---@field type "foo"
---@field name string
---@field property string
-- more unique fields
---@class Bar
---@field type "bar"
---@field name string
---@field stuff string
-- more unique fields
-- more classes
I have a function that takes an array of any of these classes as a parameter, so naturally I've unioned all of the classes.
---@alias Prototypes
---|Foo
---|Bar
-- all of the other classes
---@param prototypes Prototypes[]
local function extend(prototypes)
-- stuff and things
end
However, when I try to make prototypes a table literal, I get autocomplete for the other classes because the union operator behaves like intersection instead of union.
Is there any way to get it to show only the fields of the class indicated by the type field? I can't seem to find way to do a proper union of types.
@type seems to only work on variables, and even if it did work on table literals, it would be cumbersome to write out the type for every entry in the array.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện ví dụ Foo/Bar Prototypes[] có chú thích từ issue này và kiểm tra hành vi thu hẹp kiểu union cũng như hoàn thành table-literal của language server. Được xem là hoàn tất khi một union phân biệt được thu hẹp bằng trường type chỉ hiển thị các trường của lớp đã chọn trong phần hoàn thành, đồng thời vẫn giữ khả năng hoàn thành hợp lệ cho các thành viên union khác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- lua
- Lĩnh vực
- developer-experience, tooling
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100