Typed invitation pages
Typing a user method that returns organization invitations.
Clerk · Type Alias
ClerkPaginatedResponse is the generic interface for a method response containing a paginated list of resources. Pass the resource type as its type parameter to keep returned items strongly typed.
ClerkPaginatedResponse is a generic TypeScript interface for results returned by methods that list resources in pages. Supply the resource type as its generic argument, then use the response's collection and pagination metadata to process the current page and decide whether more data should be requested.
ClerkPaginatedResponse<T>| Name | Type | Description |
|---|---|---|
T | type parameter | The resource type contained in the paginated response. |
A paginated response interface for a list of resources.
import type { ClerkPaginatedResponse } from '@clerk/types'
type User = { id: string }
const page: ClerkPaginatedResponse<User> = {
data: [{ id: 'user_123' }],
totalCount: 1,
offset: 0,
limit: 10,
}
console.log(page.data, page.totalCount)Creates a typed paginated result whose items are User values.
Typing a user method that returns organization invitations.
Representing pages of organization memberships in application code.
Handling organization suggestions returned in pages.
ClerkPaginatedResponse is a generic interface used for the response from a method that returns a paginated list of resources. The generic parameter represents the resource type contained in that result.
Follow-up: How would you preserve type safety for organization memberships? Use ClerkPaginatedResponse<OrganizationMembershipResource> so the page items retain their resource type.
Use the type with the resource type as its generic argument, such as ClerkPaginatedResponse<User>. This lets TypeScript describe both the paginated result and the type of resources returned by the listing method.
Follow-up: What should change when the endpoint returns invitations instead? Replace User with UserOrganizationInvitationResource.
The type applies to methods that return lists, including user methods whose documentation says they return ClerkPaginatedResponse of a resource type. It should not be used as the type of one standalone resource.
Follow-up: How would you model a single user returned by a non-list method? Use that method's documented User resource return type instead of ClerkPaginatedResponse.
UserOrganizationInvitationResourceOrganizationMembershipResourceOrganizationSuggestionResource