-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Generics referencing generics #1161
Comments
You must use ---@class newClass: baseClass
local mt = Class(baseMT) |
ahh ok. I was having a problem where it wouldn't determine the type properly when I marked it as a class so that's why I didn't do that. For example, this works fine local mt = Class({test = 'str'})
mt.test -- here intellisense knows about the 'test' field however this does not. ---@class newClass
local mt = Class({test = 'str'})
mt.test -- now intellisense does not know about 'test' even though this does work fine ---@class newClass
local mt = {test = 'str'}
mt.test -- here intellisense knows about the 'test' field I looked through the code and there seems to be special handling for when the value of mt is a table, and for some reason the 2nd example does not get compiled into the table properly when it's annotated as a class. Here the |
This semantics is too complex and requires recursive generics. It is suggested to define it by |
as a work around I figured out I can change the annotations to look like this: ---@generic TBase: table
---@generic T
---@param baseClass TBase
---@param class T
---@return T|TBase
function Class(baseClass, class)
end basically this says that the |
Hi, I'm working on a project where we're using a function to construct classes which allow you to pass in an inheriting class. This function to construct a class looks something like this:
basically the class extends the base class, however I'm not sure how to do this with generics. You can see my attempt above with
---@generic T: TBase
but that doesn't work.Is this something that's currently possible or not?
The text was updated successfully, but these errors were encountered: