LuaLS / LuaLS/lua-language-server
[Feature request] User defined type guards like TypeScript's one
未關閉
還沒有人認領這個 Issue。
enhancement
feat/LuaCats Annotations
feat/type check
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- PR 合併指標
- 30 天內沒有已合併 PR
描述
As a simple example, I would like to annotate the following @guard x string. This is in effect returning a boolean, which narrows down the type of the argument x.
---@param x unknown
---@guard x string
local function isString(x)
return type(x) == "string"
end
---@param x string | number
local function main(x)
if isString(x) then
-- x is string
print(x)
else
-- x is number
print(x)
end
end
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
該 issue 沒有指定檔案、測試或進入點。首先將要求的 @guard 註解和 isString 範例與語言伺服器現有的型別縮窄行為進行比較。使用者定義的 guard 能在 true 分支將 x 縮窄為 string,並在 false 分支將其縮窄為 number,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- devtools
- Issue 類型
- 功能
- 難度
- 5/5
- 預估耗時
- 一週以上
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100