You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is intended since your implementation of button is not a covariant of widget, the error reported is accurate. However, you can achieve what you're after with types like:
---@class widget
---@field common string
---@class button : widget
---@field text string
---@field callback fun(btn: button, x: number, y: number)
---@class static__widget
local widget = {}
function widget.create()
return --[[---@type widget]] {
common = "some common field"
}
end
---@class static__button
---@field create fun(text: string, ): button
local button = {}
---@param text string
---@param callback (fun(btn: button, x: number, y: number))
function button.create(text, callback)
local button = --[[---@type button]] widget.create()
setmetatable(button, { __index = button })
button.text = text
button.callback = callback
return button
end
Basically your static class can be given its own type, that does not incorrectly indicate it inherits from the static widget type. Your button however does still correctly inherit from widget.
This is not just "correct", it's beneficial, you won't even see the create function on instances of button/widget, which is important, because they're not compatible.
The text was updated successfully, but these errors were encountered: