From 14c848959ac7ed869c76a1213304e72631b16f53 Mon Sep 17 00:00:00 2001 From: Adrian Fahrbach Date: Wed, 11 Sep 2024 22:10:56 +0200 Subject: [PATCH] feat: add generic types to get story functions --- src/index.ts | 16 ++++++++-------- src/interfaces.ts | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index 496edac2..50481a2a 100755 --- a/src/index.ts +++ b/src/index.ts @@ -224,11 +224,11 @@ class Storyblok { return this.cacheResponse(url, query, undefined, fetchOptions) } - public get( + public get( slug: string, params?: ISbStoriesParams, fetchOptions?: ISbCustomFetch - ): Promise { + ): Promise> { if (!params) params = {} as ISbStoriesParams const url = `/${slug}` const query = this.factoryParamOptions(url, params) @@ -236,12 +236,12 @@ class Storyblok { return this.cacheResponse(url, query, undefined, fetchOptions) } - public async getAll( + public async getAll( slug: string, params: ISbStoriesParams, entity?: string, fetchOptions?: ISbCustomFetch - ): Promise { + ): Promise { const perPage = params?.per_page || 25 const url = `/${slug}` const urlParts = url.split('/') @@ -299,20 +299,20 @@ class Storyblok { return Promise.resolve(this.throttle('delete', url, params, fetchOptions)) } - public getStories( + public getStories( params: ISbStoriesParams, fetchOptions?: ISbCustomFetch - ): Promise { + ): Promise> { this._addResolveLevel(params) return this.get('cdn/stories', params, fetchOptions) } - public getStory( + public getStory( slug: string, params: ISbStoryParams, fetchOptions?: ISbCustomFetch - ): Promise { + ): Promise> { this._addResolveLevel(params) return this.get(`cdn/stories/${slug}`, params, fetchOptions) diff --git a/src/interfaces.ts b/src/interfaces.ts index 9c009e8a..a7466b45 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -230,8 +230,8 @@ export interface ISbConfig { endpoint?: string } -export interface ISbResult { - data: any +export interface ISbResult { + data: T perPage: number total: number headers: Headers