Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: update Strapi5ResponseData to automatically add StrapiSystemFields #425

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/runtime/types/v5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@ export interface Strapi5RequestParams {
locale?: StrapiLocale
}

export interface Strapi5SystemFields {
export interface StrapiSystemFields {
documentId: string
locale?: StrapiLocale
locale?: string
}

export type Strapi5ResponseData<T> = Strapi5SystemFields & T
export type Strapi5ResponseData<T> = T extends object
? T extends Array<infer U>
? Array<Strapi5ResponseData<U>> // Handle arrays
: T extends Record<string, unknown>
? { [K in keyof T]: Strapi5ResponseData<T[K]> } & StrapiSystemFields
: T
: T

// Pagination interface for optional pagination info in the meta field
export interface StrapiResponseMetaPagination {
page: number
pageSize: number
}

export interface Strapi5ResponseSingle<T> {
data: Strapi5ResponseData<T>
Expand Down
Loading