What do you want to achieve? Keep it simple and clear!
I want self to use it’s own type explicitly for autocomplete/type checking purposes. This is only for script editor purposes, explicit type or not, the code will still work.
What is the issue? Include screenshots / videos if possible!
Using the implicit self, autocomplete doesn’t show me the correct functions/variables for the custom class I’m using.
Using the explicit self with a type defined, I get a warning “Function parameter 'self' already defined implicitly”
End result is I want something like this to appear when I start typing self.:
But without the warning shown above. Is there a way to do this?
local Methods: Type = {} :: Type
function Methods:Hey()
self.Test = 2
self.Test2 = 2
end
local Constructor = {}
function Constructor.new(): Type
local self = table.clone(Methods)
self.Test = "Hi"
return self
end
export type Type = {
Hey: (self: Type) -> (),
Test: string,
}
return Constructor
I personally like this way of OOP better, so I can use __index without problems.
I’m pretty sure you can also just use the typeof function, which I think is better since you won’t have to manually redefine the OOP type when you add more methods, properties, etc.
local Methods = {}
function Methods:Hey()
self.Test = 2
self.Test2 = 2
end
local Constructor = {}
function Constructor.new(): Type
local self = table.clone(Methods)
self.Test = "Hi"
return self
end
export type Type = typeof(Methods)
return Constructor