Skip to content

Instantly share code, notes, and snippets.

@killthekitten
Created November 1, 2024 14:00
Show Gist options
  • Save killthekitten/c62812fa69f2303201c36a9c2d26fd5e to your computer and use it in GitHub Desktop.
Save killthekitten/c62812fa69f2303201c36a9c2d26fd5e to your computer and use it in GitHub Desktop.
Strapi v5 TS integration
import type { Modules, Schema, UID } from '@strapi/strapi';
export type GetValues<TSchemaUID extends UID.Schema> =
Modules.Documents.Params.Attribute.GetValues<TSchemaUID>;
export type GetDynamicZoneValues<TComponentUID extends UID.Schema> =
GetValues<TComponentUID>;
export type APIResponseData<TContentTypeUID extends UID.ContentType> =
GetValues<TContentTypeUID>;
export interface APIResponseCollectionMetadata {
pagination: {
page: number;
pageSize: number;
pageCount: number;
total: number;
};
}
export interface APIResponse<TContentTypeUID extends UID.ContentType> {
// FIXME: this won't be null most of the time, but it will be null in case of an optional upload attribute.
// The Strapi utils cannot correctly infer this, so it is safer to assume all of data attributes may be null
data: APIResponseData<TContentTypeUID> | null;
}
export interface APIResponseCollection<
TContentTypeUID extends UID.ContentType
> {
data: APIResponseData<TContentTypeUID>[];
meta: APIResponseCollectionMetadata;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment