I have some "branded" tuple types in my code. They're just tuples, but I've added some properties so the type system will prevent them from getting them confused with eachother. (Ex: A GridPoint can't be passed into a function expecting a PixelPoint and vice-versa, even though they're both actually just [number, number] types).
But because this branding adds a property to the type, they're no longer tuple types as far as the checker is concerned. So I can't spread them anymore! If I do:
export type UnitPoint<Name extends string> = [number, number] & {
__brand?: Name;
};
function foo(x: number, y: number): void {
console.log(x, y);
}
const a: UnitPoint<"GridPoint"> = [1, 2];
foo(...a);
I get the error:
A spread argument must either have a tuple type or be passed to a rest parameter.
I can fix this at each callsite with foo(...a as [number, number]) but I'm wondering if there's a way to modify my type so that the checker knows that its actually just a tuple for this purpose.