From d095ac9f7067fa1098330af663de62e99ff052f5 Mon Sep 17 00:00:00 2001 From: Luis Alvarez Date: Mon, 5 Oct 2020 01:13:20 -0500 Subject: [PATCH] Updated types --- .../api/operations/get-all-product-paths.ts | 21 ++++++++++++------- .../api/operations/get-all-products.ts | 18 +++++++++------- lib/bigcommerce/api/operations/get-product.ts | 2 +- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/bigcommerce/api/operations/get-all-product-paths.ts b/lib/bigcommerce/api/operations/get-all-product-paths.ts index d5d91a00d..7a9f49b23 100644 --- a/lib/bigcommerce/api/operations/get-all-product-paths.ts +++ b/lib/bigcommerce/api/operations/get-all-product-paths.ts @@ -16,17 +16,22 @@ export const getAllProductPathsQuery = /* GraphQL */ ` } ` -export interface GetAllProductPathsResult { - products: T extends GetAllProductPathsQuery - ? NonNullable - : unknown -} +export type ProductPaths = NonNullable< + GetAllProductPathsQuery['site']['products']['edges'] +> + +export type GetAllProductPathsResult< + T extends { products: any[] } = { products: ProductPaths } +> = T async function getAllProductPaths(opts?: { config?: BigcommerceConfig -}): Promise> +}): Promise -async function getAllProductPaths(opts: { +async function getAllProductPaths< + T extends { products: any[] }, + V = any +>(opts: { query: string config?: BigcommerceConfig }): Promise> @@ -37,7 +42,7 @@ async function getAllProductPaths({ }: { query?: string config?: BigcommerceConfig -} = {}): Promise> { +} = {}): Promise { config = getConfig(config) // RecursivePartial forces the method to check for every prop in the data, which is // required in case there's a custom `query` diff --git a/lib/bigcommerce/api/operations/get-all-products.ts b/lib/bigcommerce/api/operations/get-all-products.ts index 23ed87667..db7dd406a 100644 --- a/lib/bigcommerce/api/operations/get-all-products.ts +++ b/lib/bigcommerce/api/operations/get-all-products.ts @@ -37,11 +37,13 @@ export const getAllProductsQuery = /* GraphQL */ ` ${productInfoFragment} ` -export interface GetAllProductsResult { - products: T extends GetAllProductsQuery - ? NonNullable - : unknown -} +export type Products = NonNullable< + GetAllProductsQuery['site']['products']['edges'] +> + +export type GetAllProductsResult< + T extends { products: any[] } = { products: Products } +> = T export type ProductVariables = Images & Omit @@ -49,9 +51,9 @@ export type ProductVariables = Images & async function getAllProducts(opts?: { variables?: ProductVariables config?: BigcommerceConfig -}): Promise> +}): Promise -async function getAllProducts(opts: { +async function getAllProducts(opts: { query: string variables?: V config?: BigcommerceConfig @@ -65,7 +67,7 @@ async function getAllProducts({ query?: string variables?: ProductVariables config?: BigcommerceConfig -} = {}): Promise> { +} = {}): Promise { config = getConfig(config) const variables: GetAllProductsQueryVariables = { ...config.imageVariables, diff --git a/lib/bigcommerce/api/operations/get-product.ts b/lib/bigcommerce/api/operations/get-product.ts index 89acc7aa7..4f052bbee 100644 --- a/lib/bigcommerce/api/operations/get-product.ts +++ b/lib/bigcommerce/api/operations/get-product.ts @@ -50,7 +50,7 @@ async function getProduct(opts: { config?: BigcommerceConfig }): Promise -async function getProduct(opts: { +async function getProduct(opts: { query: string variables: V config?: BigcommerceConfig