I have two code examples.
example a:
--!strict
local object = {}
object.__index = object
local self : object
function object.new(Number : number?) : object
local self = setmetatable({},object)
self.var = Number
return self
end
function object:doThing()
self.var = 500
end
type object = typeof(object.new())
return object
and example b:
--!strict
local object = {}
object.__index = object
local self : object
function object.new(Number : number?) : object
local self = setmetatable({},object)
self.var = Number
return self
end
function object:doThing()
local self : object = self
self.var = 500
end
type object = typeof(object.new())
return object
The only difference is that in class methods and specifically class methods, to get the convenience of knowing what is stored in self, I notated that self is an object and it is equal to self.
Why is this a big deal? it's not. I just really like not having to constantly go back to check what variables and methods and whatnot are and are not in objects of a class. You'll see this yourself if you plug in the code to a module and type "self.", in which it'll bring up all the items stored in self. But that behavior is not extended to the scope of class methods.
So I was wondering if there was anything I could do to get said convenience of the type notation without having to write that one line at the start of every method. If you don't know or it's literally impossible, that's fine. It's really no big deal.