4
0
forked from crowetic/commerce

Fixed types

This commit is contained in:
Luis Alvarez 2021-02-25 17:18:50 -05:00
parent 46ae76c67f
commit e90d9a2121
9 changed files with 28 additions and 23 deletions

View File

@ -1,7 +1,5 @@
import { Page } from '../../schema'
import { ShopifyConfig, getConfig } from '..'
import type { Page } from '../../types'
export type { Page }
export type GetPageResult<T extends { page?: any } = { page?: Page }> = T

View File

@ -40,7 +40,8 @@ export const handler: MutationHook<Cart, {}, CartItemBody> = {
},
})
return checkoutToCart(checkoutLineItemsAdd)
// TODO: Fix this Cart type here
return checkoutToCart(checkoutLineItemsAdd) as any
},
useHook: ({ fetch }) => () => {
const { mutate } = useCart()

View File

@ -1,6 +1,4 @@
import { useMemo } from 'react'
import type { ShopifyProvider } from '..'
import useCommerceCart, {
FetchCartInput,
UseCart,
@ -11,7 +9,7 @@ import { SWRHook } from '@commerce/utils/types'
import { checkoutCreate, checkoutToCart } from './utils'
import getCheckoutQuery from '../utils/queries/get-checkout-query'
export default useCommerceCart as UseCart<ShopifyProvider>
export default useCommerceCart as UseCart<typeof handler>
export const handler: SWRHook<
Cart | null,
@ -38,7 +36,8 @@ export const handler: SWRHook<
checkout = await checkoutCreate(fetch)
}
return checkoutToCart({ checkout })
// TODO: Fix this type
return checkoutToCart({ checkout } as any)
},
useHook: ({ useData }) => (input) => {
const response = useData({

View File

@ -24,7 +24,8 @@ const fetcher: HookFetcherFn<Cart | null, FetchCartInput> = async ({
checkout = await checkoutCreate(fetch)
}
return checkoutToCart({ checkout })
// TODO: Fix this type
return checkoutToCart({ checkout } as any)
}
export default fetcher

View File

@ -2,9 +2,9 @@ import useCustomer, { UseCustomer } from '@commerce/customer/use-customer'
import { Customer } from '@commerce/types'
import { SWRHook } from '@commerce/utils/types'
import { getCustomerQuery, getCustomerToken } from '../utils'
import type { ShopifyProvider } from '..'
export default useCustomer as UseCustomer<ShopifyProvider>
export default useCustomer as UseCustomer<typeof handler>
export const handler: SWRHook<Customer | null> = {
fetchOptions: {
query: getCustomerQuery,

View File

@ -30,9 +30,6 @@ export type CartItemBody = Core.CartItemBody & {
optionSelections?: OptionSelections
}
type X = Core.CartItemBody extends CartItemBody ? any : never
type Y = CartItemBody extends Core.CartItemBody ? any : never
export type GetCartHandlerBody = Core.GetCartHandlerBody
export type AddCartItemBody = Core.AddCartItemBody<CartItemBody>

View File

@ -1,4 +1,8 @@
import { Product, Image } from '../types'
// TODO: Fix the types in this file
// import { Product, Image } from '../types'
type Product = any
type Image = any
export default function toCommerceProducts(products: Product[]) {
return products.map((product: Product) => {
@ -20,10 +24,12 @@ export default function toCommerceProducts(products: Product[]) {
url: image.src,
}
}),
variants: product.variants.map((variant) => {
// TODO: Fix the variant type
variants: product.variants.map((variant: any) => {
return {
id: variant.id,
options: variant.selectedOptions.map((selectedOption) => {
// TODO: Fix the selectedOption type
options: variant.selectedOptions.map((selectedOption: any) => {
return {
__typename: 'MultipleChoiceOption',
displayName: selectedOption.name,
@ -39,11 +45,13 @@ export default function toCommerceProducts(products: Product[]) {
}),
}
}),
productOptions: product.options.map((option) => {
// TODO: Fix the option type
productOptions: product.options.map((option: any) => {
return {
__typename: 'MultipleChoiceOption',
displayName: option.name,
values: option.values.map((value) => {
// TODO: Fix the value type
values: option.values.map((value: any) => {
return {
node: {
entityId: 1,

View File

@ -1,5 +1,7 @@
// TODO: replace this hook and other wishlist hooks with a handler, or remove them if
// Shopify doesn't have a wishlist
import { HookFetcher } from '@commerce/utils/types'
import { SwrOptions } from '@commerce/utils/use-data'
import useCommerceWishlist from '@commerce/wishlist/use-wishlist'
import { Product } from '../schema'
import useCustomer from '../customer/use-customer'
@ -31,7 +33,8 @@ export const fetcher: HookFetcher<Wishlist | null, UseWishlistInput> = () => {
export function extendHook(
customFetcher: typeof fetcher,
swrOptions?: SwrOptions<Wishlist | null, UseWishlistInput>
// swrOptions?: SwrOptions<Wishlist | null, UseWishlistInput>
swrOptions?: any
) {
const useWishlist = ({ includeProducts }: UseWishlistOptions = {}) => {
return { data: null }

View File

@ -39,5 +39,3 @@ module.exports = withCommerceConfig({
].filter((x) => x)
},
})
console.log('configs', module.exports)