I’m trying out annotations for the first time & doing my best to integrate it with magnalite’s method of abstraction & object creation. Although the base class is functional, I can’t figure out how I would annotate an inherited class, if that’s even at all possible.
Base Object Class:
--!strict
-- Module Table
local Object = {}
Object.__index = Object
-- Object Type
type ObjectType = typeof(setmetatable({}, Object))
--[[ Constructor: Returns an instance of the ObjectType class. ]]
function Object.new(arg1: number, arg2: boolean): ObjectType
local self = setmetatable({}, Object)
-- Properties
self.Number = arg1
self.Bool = arg2
return self
end
--[[ Get Number: Returns the object's number. ]]
function Object:getNumber(): number self = self::ObjectType
return self.Number :: number
end
--[[ Get Number: Returns the object's bool. ]]
function Object:getBool(): boolean self = self::ObjectType
return self.Bool :: boolean
end
-- Module Table
return Object
Inherited Object Class:
--!strict
-- Parent Class
local BaseObject = require(script.Parent)
-- Module Table
local inheritedObject = setmetatable({}, BaseObject)
inheritedObject.__index = inheritedObject
-- Object Type
type inheritedObjectType = typeof(setmetatable({}, BaseObject)) & typeof(setmetatable({}, inheritedObject))
-- Colour Type
type colour = "blue"| "red" | "green"
--[[ Constructor: Returns an instance of the inheritedObjectType class ]]
function inheritedObject.new(arg1: number, arg2: boolean, arg3: colour): inheritedObjectType
local self = setmetatable({BaseObject.new(arg1,arg2)}, inheritedObject) :: inheritedObjectType
-- Properties
self.Colour = arg3
return self
end
--[[ Get Colour: Returns the object's colour. ]]
function inheritedObject:getColour(): colour self = self::inheritedObjectType
return self.Colour :: colour
end
-- Module Table
return inheritedObject
Currently the InheritedObject class will only autofill for the base class’s functions & properties while not allowing me to add any new ones either. It doesn’t override the base functions either. I would appreciate any kind of explanations or possible errors I could’ve made.