commerce icon indicating copy to clipboard operation
commerce copied to clipboard

Make our core types not extendable

Open lfades opened this issue 4 years ago • 0 comments
trafficstars

You can read more about why we want to do this here: https://github.com/vercel/commerce/issues/429

All our core types include a TS generic that has the base types that might be used by the schema, once our other tasks in https://github.com/vercel/commerce/issues/429 are done we would like to remove the usage of generics from our core types.

E.g the AddItemHook would change from:

export type AddItemHook<T extends CartTypes = CartTypes> = {
  data: T['cart']
  input?: T['itemBody']
  fetcherInput: T['itemBody']
  body: { item: T['itemBody'] }
  actionInput: T['itemBody']
}

to:

export type AddItemHook = {
  data: Category
  input?: CartItemBody
  fetcherInput: CartItemBody
  body: { item: CartItemBody }
  actionInput: CartItemBody
}

We can eventually find a way of converting our types into interfaces, but that might cause a few issues at the moment due to the Provider type being defined by a generic too and TS complains about it. We can try that one later.

lfades avatar Sep 30 '21 23:09 lfades