Skip to content

Commit

Permalink
types: update Strapi5ResponseData to automatically add `StrapiSyste…
Browse files Browse the repository at this point in the history
…mFields` (#425)
  • Loading branch information
XanderD99 authored Sep 27, 2024
1 parent b8949e5 commit 84b7e19
Showing 1 changed file with 15 additions and 3 deletions.
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

0 comments on commit 84b7e19

Please sign in to comment.