type UserIdentifier = ExactlyOneOf<{
id: string;
email: string;
username: string;
}>;
// Valid usage
const user1: UserIdentifier = { id: "123" };
const user2: UserIdentifier = { email: "test@example.com" };
const user3: UserIdentifier = { username: "user123" };
// Invalid usage
const user4: UserIdentifier = {}; // Error: At least one property is required
const user5: UserIdentifier = { id: "123", email: "test@example.com" }; // Error: Only one property allowed
A utility type that enforces exactly one property from
Tto be set.This ensures that:
If multiple properties are specified, TypeScript will produce an error. If no properties are specified, TypeScript will also produce an error.