Brand your ids so a UserId cannot be an OrderId
Two ids that are both string will be swapped in an argument list eventually and the compiler will say nothing.
type UserId = string & { readonly __brand: "UserId" };
type OrderId = string & { readonly __brand: "OrderId" };
const userId = (s: string) => s as UserId;Now getOrder(userId) is a type error. Zero runtime cost, one line per id type, and it catches the class of bug that tests almost never do.
typescript