lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Annotations with mixins?

Open distantforest1 opened this issue 2 years ago • 1 comments

Hi I'm trying to make annotations that must require the user to have certain fields in a table as a requirement.

For instance, I want a table that needs to have x,y fields, or certain functions.

Here is some pseudo-code that might explain what I mean:

---@class Spinnable
---@field spin fun()

---@class Positionable
---@field x number
---@field y number
---@field setPos fun(x: number, y: number)

---@generic T : Spinnable, Positionable
---@param p1 `T`
---@return T
local function doFunction(p1) return p1 end

local entity = { x = 5 }          -- A table that is missing the other fields
local check = doFunction(entity) -- I want a warning here saying it doesn't have, `y`, `setPos()`, or `spin()`

Is this currently possible to require certain fields in a table?

distantforest1 avatar Jan 30 '23 10:01 distantforest1

This would be a really great addition! Currently the only issue im running into.

morgverd avatar Mar 13 '24 16:03 morgverd