Skip to content

Problem with generics #911

Open
Open
@lua-rocks

Description

@lua-rocks

I have reported a similar problem before and I understand that it is not simple, but if you solve it, I will be crazy happy!

I'm working on an OOP library and here's a truncated example of the constructor it uses:

---@generic T
---@param t1 T
---@param t2 T
---@return T
function new(t1, t2) end

The first table here is the class from which the instance will inherit, and the second is the additional settings that will be substituted to the instance. So all tables has the same type.

When I call this constructor, the generics work almost correctly - the result of this function has the same type as any argument:

---@class Example1
---@field e1a string
---@field e1b string
local Example1 = {}

---@class Example2
---@field e2a string
---@field e2b string
local Example2 = {}

local e = new(Example1, {}) -- e is Example1
local e = new(Example2, {}) -- e is Example2
local e = new({}, Example1) -- e is Example1
local e = new({}, Example2) -- e is Example2

But the problem is that when I start typing a text between the curly braces in the example above, I get no hints about the class fields. Maybe I'm describing generics wrong? Do you have any idea? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestfeat/genericRelated to generic emulation feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions