Before replying, please remember strictmode is enabled for all scripts in this post.
I am attempting to implement class inheritance with strictmode type checking and running into some issues, specifically with Studio’s native autocomplete.
I have the following module (InheritedObject):
--!strict
local Object = require(script.Parent)
local _module = setmetatable({}, Object)
_module.__index = _module
export type InheritedObject = typeof(setmetatable({} :: {
newAttr: number
}, _module)) & Object.Object
function _module.new(public: boolean, new: number): InheritedObject
local self = setmetatable(Object.new(public) :: InheritedObject, _module)
self.newAttr = new
self:newMethod()
return self
end
function _module:newMethod(): ()
print("New method called")
end
return _module
The problem is calling a method of the new class (NOT the class it is inheriting from):
self:newMethod()
The IDE does not throw any errors or warnings, and it works perfectly fine if I playtest it. However, the autocomplete does not show :newMethod()
as a valid method of self
.
It only shows the methods it inherited.
I thought, maybe the issue is the autocomplete has no idea newMethod
actually exists, since it’s defined later in the script. So I defined a type just for the module…
type InheritedObjectProvider = typeof(setmetatable({} :: {
__index: InheritedObjectProvider,
new: (public: boolean, new: number) -> InheritedObject,
newMethod: (self: InheritedObject) -> ()
}, Object))
…which just didn’t work.
Since this isn’t a critical issue because the module runs perfectly fine, I can just deal with it if nothing can be done. However, I would prefer for the autocomplete to… work, though? Any ideas?
Thanks in advance,
Fizzitix