LuaLS / LuaLS/lua-language-server

Type Narrow Exact Strings

オープン
#2,219 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Issue の Lua 例が提供されている唯一のエントリーポイントです。これを使って、test と test1 の現在の型を再現してください。"test_group_a" との等価性チェックによって test が TestTable のインデックスに使えるところまで絞り込まれ、test1 が string として推論されること(提示されたケースのカバレッジを含む)が完了の条件です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
compilers, devtools
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。