I like the tricks :) – Kasia
Moving authorization from value to type level can make your code simpler and bullet-proof.
type MemberKind = "user"
type User = { _kind: "admin" } | { _kind: "editor" } | { _kind: MemberKind }
type FilterPrivileged<U extends User> = U extends { _kind: MemberKind } ? never : U
type Privileged = FilterPrivileged<User>
const dropDatabase = (performedBy: Privileged) => {
// ...
}
dropDatabase(member) // ✅ Does not compile
Crafted with 💛 by Riccardo
Crafted with 💛 by Riccardo