LuaLS / LuaLS/lua-language-server
Type Narrow Exact Strings
未关闭
还没有人认领这个 Issue。
enhancement
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
Another feature suggestion 😅
It would be useful to be able to type-narrow exact strings.
For example:
---@alias TestTable {test_group_a: {test_field_1: string, test_field_2: string}, test_group_b: {test_field_1: string, test_field_3: string}}
---@type "test_group_a" | "test_group_b"
local test
if test == "test_group_a" then
---@type TestTable
local test_table
test1 = test_table[test].test_field_1
end
When we do if test == "test_group_a" then it would be nice if the type of test narrowed to test_group_a (which can then be used to successfully index test_table. As it is now there is no type narrowing so the inferred type of test1 is unknown when it should be string.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
issue 中的 Lua 示例是唯一提供的入口点;使用它来复现 test 和 test1 当前的类型。完成的标准是:与 "test_group_a" 进行相等性检查后,test 被收窄到足以索引 TestTable,并推断 test1 为 string,同时覆盖所示情形。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- compilers, devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100