Skip to content

RoleNameOf

RoleNameOf<P> = P extends Permissions<infer R> ? R extends readonly infer X[] ? X extends string ? X : string : string : string

Defined in: packages/auth/src/types.ts:16

Extracts the role string-literal union from a Permissions object.

definePermissions({ roles: ["admin", "user"] as const, ... }) produces a Permissions<readonly ["admin", "user"]>. Feeding that into this helper yields the union "admin" | "user", which is what we use to type AuthConfig.defaultRoles / AuthConfig.anonymousRoles so passing an unknown role becomes a TS error instead of a runtime surprise.

When the caller passes a loosely-typed Permissions<readonly string[]> (e.g. imported from a dynamic module), this resolves to string and the existing lenient behavior is preserved.

P