LuaLS / LuaLS/lua-language-server
---@class with function return question
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
so I have this (as a mockup):
```lua
do
---@class a
local a = {}
---@generic T
---@param self a
---@param new T
---@return T
a.extend = function(self, new)
--...
return new
end
end
```
and it's supposed to be inheritance for prototypes, right, but I'm trying to make the LS think that it returns the second parameter `new` and it does that and the LS thinks that, so far so good. So this
```lua
local b = a:extend{
n = 1
}
```
will make it like this:

but the problem is, that if I use `---@class b` here, then it will ignore what the function returns and I get this:

am I missing something or is it just not possible? Though, if I separate it into two statements like this,
```lua
---@class b
local b = {
n = 1
}
b = a:extend(b)
```
then I get what I want:

but it's not ideal, since it's two statements now and I can't use the `fun{}` syntactic sugar this way, which would be the whole reason, right. Is there a way to make it work? Also I'm unsure about how to properly word the title here
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 nombran archivos fuente ni pruebas. Reproduce los dos fragmentos de Lua de una línea y los dos de dos instrucciones; después, sigue la inferencia de tipos de LuaLS para declaraciones locales, anotaciones de clase, genéricos y valores de retorno de funciones. Se considera terminado cuando el comportamiento compatible está implementado y cubierto por una prueba de regresión, o cuando la limitación está documentada claramente.
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