LuaLS / LuaLS/lua-language-server
Type Narrow Exact Strings
Nessuno ha ancora preso questa issue.
- Lingua principale
- Lua
- Stelle
- 4.4k
- Fork
- 442
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
L'esempio Lua dell'issue è l'unico punto di ingresso fornito; usalo per riprodurre i tipi attuali di test e test1. Il lavoro è completato quando un controllo di uguaglianza con "test_group_a" restringe test a sufficienza da consentire l'indicizzazione di TestTable e inferire test1 come string, includendo la copertura del caso mostrato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- lua
- Ambito
- compilers, devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100