Any way to restrict the possible types of a Generic/Template?

Dose anyone know of a way to restrict the possible types for a Generic? An example of this would be:

function foo<T: Vector2 | Vector3>(mainPoint: T, points: {T}): T
    ...
end


If not i would be fine to just do this instead:

type Vector = Vector2 | Vector3

function foo(mainPoint: Vector, points: {Vector}): Vector
    ...
end

As far as I know, Luau currently does not support generic constraints. There are a couple RFCs for them though, and they do plan on implementing them. I don’t think there’s an exact timeline for it though

1 Like