Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with generics #911

Open
lua-rocks opened this issue Jan 18, 2022 · 1 comment
Open

Problem with generics #911

lua-rocks opened this issue Jan 18, 2022 · 1 comment
Labels
enhancement New feature or request feat/generic Related to generic emulation feature

Comments

@lua-rocks
Copy link

lua-rocks commented Jan 18, 2022

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!

@sumneko sumneko added the enhancement New feature or request label Jan 24, 2022
@sumneko
Copy link
Collaborator

sumneko commented Jun 30, 2022

Generic can not work on param now.

@carsakiller carsakiller added the feat/generic Related to generic emulation feature label Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feat/generic Related to generic emulation feature
Projects
None yet
Development

No branches or pull requests

3 participants
  翻译: