lua-language-server
lua-language-server copied to clipboard
Infer the type of the returned expression from the return type declaration
The situation:
---@class Test
---@field foo number
---@return Test
local function test()
return {
foo = 'this is not a number!',
}
end
The code passes as valid when in reality the field is assigned a wrong type of value.
Right now the workaround is to do
---@class Test
---@field foo number
---@return Test
local function test()
---@type Test
return {
foo = 'this is not a number!',
}
end
which to me feels like belaboring the obvious. Would be great if LuaLS assumed this automatically.