Generalize TypeScript and add typings to getPage

This commit is contained in:
tniezg
2021-08-30 14:38:23 +02:00
parent 490f94b515
commit 320fc0645d
5 changed files with 54 additions and 21 deletions

View File

@@ -8,17 +8,19 @@ import type {
JsonApiSingleResponse,
} from '@spree/storefront-api-v2-sdk/types/interfaces/JsonApi'
import getSpreeSdkMethodFromEndpointPath from '../../utils/get-spree-sdk-method-from-endpoint-path'
import { SpreeSdkVariables } from 'framework/spree/types'
import SpreeSdkMethodFromEndpointPathError from 'framework/spree/errors/SpreeSdkMethodFromEndpointPathError'
import { GraphQLFetcher, GraphQLFetcherResult } from '@commerce/api'
import createCustomizedFetchFetcher from '../../utils/create-customized-fetch-fetcher'
import fetch, { Request } from 'node-fetch'
const createApiFetch: (
export type CreateApiFetch = (
getConfig: () => SpreeApiConfig
) => GraphQLFetcher<GraphQLFetcherResult<any>, SpreeSdkVariables> = (
_getConfig
) => {
) => GraphQLFetcher<GraphQLFetcherResult<any>, any>
// TODO: GraphQLFetcher<GraphQLFetcherResult<any>, any> should be GraphQLFetcher<GraphQLFetcherResult<any>, SpreeSdkVariables>.
// But CommerceAPIConfig['fetch'] cannot be extended from Variables = any to SpreeSdkVariables.
const createApiFetch: CreateApiFetch = (_getConfig) => {
const client = makeClient({
host: requireConfigValue('apiHost') as string,
fetcherType: 'custom',