I present to you, my way of auto type checking classes created with your standard OOP structure. Not sure if this is good practice, but I discovered it trying to be as lazy as possible, I couldn’t find any post about doing it this way but yea here it is.
local Class = {}
Class.__index = Class
function Class.new(): Class_Type
local self = {}
return setmetatable(self, Class) :: typeof(self) & typeof(Class)
end
function Class:Test()
self = self :: Class_Type
end
export type Class_Type = typeof(Class.new())
return Class
Essentially you have your standard setup except you have the export type at the bottom, which is a but unusual, but it’s needed to make it work.
But now whenever you add a variable into the self table defined in the “.new” function, the other functions will recognize it and add it to the type allowing for super easy autofill with the least amount of effort possible.
hello . Is it me or roblox autocomplete nolonger supports autocomplete for classes?
eg)
local module = {}
module.__index = module
function module.new()
local self = setmetatable({},module)
self.Foo = "Foo"
self:init()
return self
end)
function module:init()
--foo is not recgonise in self
end)
return module