How do you apply type checking to a general quadratic bezier function?

Hi,

I’m just wondering how I would specify a type for a quadratic bezier function that accepts any interpolate-able value and to ascertain that the function call is valid? Currently I have a function that just calls each of their lerp methods doing p0:lerp(p1:lerp(p2, t), t). The issue is that when I try assigning a type to the variables p0, p1 and p2, it just gives me type checking errors. Is it possible to do what I’m trying to do?

Currently, the type Interpolatable is specified as CFrame | Vector3 | Vector2 | UDim2 | Color3, all of which have Lerp methods. Any ideas to get rid of the type checking errors?

I’ve tried using & instead of |, but I still get type checking errors on the other side, when trying to call the method, stating that type isn’t compatible.

Edit: I think I found a solution by doing a hacky type assertion thing but I’m still not sure it’s the proper solution:

Bumping,

I think I would want to use generics for this but again not sure because everything I’ve used seems to give some error.

For example:

function module.quadraticBezier<T>(p0: T, p1: T, p2: T, time: number)
	return p0:Lerp(p1, time):Lerp(p1:Lerp(p2, time), time) :: typeof(p0)
end

From that I get "Type T does not have key “Lerp”

export type lerpable<t> = {
	Lerp: ( self: t, other: t, alpha: number ) -> t;
}

function module.quadraticBezier<t>(p0: lerpable<t>, p1: lerpable<t>, p2: lerpable<t>, time: number)
	return p0:Lerp(p1, time):Lerp(p1:Lerp(p2, time), time) :: typeof(p0)
end

From that I get “Type t does not have key Lerp”

This is the closest I’ve gotten

But when you call it with a Vector3, lo and behold another error.
image

So I tried adding | Vector3 to the type, and guess what, another error!

So now I’m stuck anyone have any ideas or insight?