-
-
Notifications
You must be signed in to change notification settings - Fork 376
Closed as not planned
Description
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
MacOS
What is the issue affecting?
Completion
Expected Behaviour
Methods Peek,Push,Pop
have proper type hints
Actual Behaviour
While types of a, b, c
are correct the
type hints of methods are unusable with unnecessary union types.
If Push
is removed from superclass, then type hints go to normal without unions but still with <T>
in many places
local _lua_setmetatable = setmetatable
Stack = {}
--- @generic T
--- @class Stack<T> : {
--- Pop: (fun(self: Stack<T>): T),
--- Peek: (fun(self: Stack<T>): T),
--- Push: (fun(self: Stack<T>, value: T): Stack<T>),
--- }
--- @field protected _stack any[]
--- @field protected _count integer
Stack.__index = {}
--- Creates a new, empty stack.
--- @generic T
--- @return Stack<T>
function Stack.New()
local this = {
_stack = {},
_count = 0,
}
return _lua_setmetatable(this, Stack)
end
local st = Stack.New() --[[@as Stack<{ num: integer }>]]
local a = st:Peek()
local b = st:Pop()
local c = st:Push({})

Reproduction steps
Analyze specified code in VSCode with luals installed
Additional Notes
No response
Log File
No response
Metadata
Metadata
Assignees
Labels
No labels