I am currently trying to make a Vector4 module, but I run into some issues with the type checker. Nothing actually breaks, it’s just really annoying. The constructor and type look something like this:
export type Vector4 = {
X: number,
Y: number,
Z: number,
W: number,
__type: string,
-- Needed to allow error less indexing of Magnitude and Unit
Magnitude: number?,
Unit: Vector4?,
__add: nil | (Vector4, Vector4) -> Vector4,
__mul: nil | (Vector4, Vector4 | number) -> Vector4,
__div: nil | (Vector4, Vector4 | number) -> Vector4,
__sub: nil | (Vector4, Vector4) -> Vector4,
Lerp: nil | (Vector4, Vector4) -> Vector4
}
function Vector4.new(X: number?, Y: number?, Z: number?, W: number?): Vector4
local X: number = X or 0
local Y: number = Y or 0
local Z: number = Z or 0
local W: number = W or 0
local self: Vector4 = {
X = X,
Y = Y,
Z = Z,
W = W,
__type = TYPE_STRING
}
return setmetatable(self, Vector4)
end
function Vector4:Lerp()
-- how lerp works doesn't really matter --
end
When I try to call the lerp method, I get a type checking something along the lines of
Cannot call a non function
Is there a way to make the type checker recognize that the Lerp
method exists?