LuaLS / LuaLS/lua-language-server
Problem with generics
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Lua
- Estrellas
- 4.4k
- Forks
- 442
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
I have reported a similar problem before and I understand that it is not simple, but if you solve it, I will be crazy happy!
I'm working on an OOP library and here's a truncated example of the constructor it uses:
---@generic T
---@param t1 T
---@param t2 T
---@return T
function new(t1, t2) end
The first table here is the class from which the instance will inherit, and the second is the additional settings that will be substituted to the instance. So all tables has the same type.
When I call this constructor, the generics work almost correctly - the result of this function has the same type as any argument:
---@class Example1
---@field e1a string
---@field e1b string
local Example1 = {}
---@class Example2
---@field e2a string
---@field e2b string
local Example2 = {}
local e = new(Example1, {}) -- e is Example1
local e = new(Example2, {}) -- e is Example2
local e = new({}, Example1) -- e is Example1
local e = new({}, Example2) -- e is Example2
But the problem is that when I start typing a text between the curly braces in the example above, I get no hints about the class fields. Maybe I'm describing generics wrong? Do you have any idea? Thanks!
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
No se nombra ningún archivo fuente ni ninguna prueba. Reproduce el ejemplo de constructor genérico en el Lua language server e inspecciona cómo se infiere la finalización dentro de los argumentos de tabla vacíos cuando el primer argumento es Example1 o Example2. Se considera terminado cuando se sugieren los campos de clase relevantes en esos literales de tabla, preservando al mismo tiempo el tipo de resultado inferido existente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- lua
- Área
- devtools
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100