(role: string | null | undefined, capability: Capability)
| 34 | * throwing, so callers never have to validate it first. |
| 35 | */ |
| 36 | export function can(role: string | null | undefined, capability: Capability): boolean { |
| 37 | if (!isRole(role)) return false |
| 38 | // `satisfies` narrows each array to a tuple of its own literals, so the cast |
| 39 | // widens it back to the full Capability union for `includes`. |
| 40 | return (roles[role] as readonly Capability[]).includes(capability) |
| 41 | } |
| 42 | |
| 43 | /** Whether a string is a known role name. */ |
| 44 | export function isRole(role: string | null | undefined): role is Role { |
no test coverage detected