Luau typechecking and intellisense documentation for modules with overloaded functions

Trying to write my own math library for personal use, but I have some issues with typechecking and documentation.

type lerpType<T> = (T, T, number) -> T
local MATH = {}

-- Linear interpolation.
MATH.lerp = function(a, b, t)
    -- Boring code...
end:: lerpType<number>
& lerpType<Vector2>
& lerpType<Vector3>
& -- ...

But it just refuses to work. Neither the documentation nor the type shows up in intellisense.
Any solutions/workarounds?

yeah roblox luau’s typechecking is really bad and stuff like this that’s obviously a bug with very weird work arounds are so annoying. for some reason the autofill only decided it wanted to work when you manually type out the function type definitions so like,

local MATH = {}

-- Linear interpolation.
MATH.lerp = function(a, b, t)
	-- Boring code...
end :: ((number, number, number) -> number) 
& ((Vector2, Vector2, number) -> Vector2) 
& ((Vector3, Vector3, number) -> Vector3)

MATH.lerp() -- cool

but even if you do this apparently luau’s beast of a type checker cant understand that the documentation above the function is supposed to just be applied to the overloads so for that i had to get a little more creative,

local MATH = {}

-- description1
local function func1(a : number, b : number, t : number): number end

-- description2
local function func2(a : Vector2, b : Vector2, t : number): Vector2 end

-- description3
local function func3(a : Vector3, b : Vector3, t : number): Vector3 end

-- Linear interpolation.
MATH.lerp = function(a, b, t)
	-- Boring code...
end :: typeof(func1)
& typeof(func2)
& typeof(func3)

MATH.lerp() -- cool

this is such a roundabout and ridiculous work around but it does work (probably not even worth it at this point). anyways if someone finds a more efficient/cleaner way to do this lmk.

Would you mind elaborate on or repeat how to do this? I can’t seem to get it to work.

Also I have just realized that math.lerp has been added literally 16 days ago, confusing the type checker.

Nevermind, got it to work by putting the type definition before the function declaration. Thank you for your solution!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.