Hydrogen - Storefront API response types - Typescript

rwilabs
Visitor
1 0 0

Hey everyone, could somebody point me in the direction of where I could find a list of types for storefront api responses? Currently following along the hydrogen tutorial but it's not written in typescript... Thanks!

Helping businesses achieve success online
Reply 1 (1)
yellowbrickcode
Shopify Partner
5 1 0

I know this is an old one, but I found it when searching for this answer myself, so wanted to leave an answer now that I've found one.

 

Each type returned from the Storefront API has a corresponding Typescript type (which is already included if you chose Typescript when creating your Hydrogen project). For example, if you're retrieving `collections` from the API, you can see in the docs here, that returns a `CollectionConnection`. To use that type in your Typescript, you add this import to the top of your TS file:

import type {CollectionConnection} from '@shopify/hydrogen-react/storefront-api-types';

You can now use this type in your TS code and get intellisense.