thetrevorharmon / gatsby-theme-shopify-manager

The easiest way to start a Shopify shop on Gatsby.
https://gatsby-theme-shopify-manager.netlify.app/
MIT License
120 stars 11 forks source link

gatsby-theme-shopify-manager has an implicit 'any' type #62

Open schwartzmj opened 4 years ago

schwartzmj commented 4 years ago

I'm not receiving type information for gatsby-theme-shopify-manager in Webstorm. Here's the error: TS7016: Could not find a declaration file for module 'gatsby-theme-shopify-manager'. '/Users/myusername/Dev/myproject/node_modules/gatsby-theme-shopify-manager/index.js' implicitly has an 'any' type.   Try 'npm install @types/gatsby-theme-shopify-manager' if it exists or add a new declaration (.d.ts) file containing 'declare module 'gatsby-theme-shopify-manager';

I noticed that index.js at the project root is a one-liner that exports everything from src/index.ts. I found that if instead of doing import { useCart } from "gatsby-theme-shopify-manager";, I do: import { useCart } from "gatsby-theme-shopify-manager/src";, then I get all of the proper type information. I also found that if I rename the file from index.js to index.ts I get all the types.

Having not created a project like this before, I'm not sure what the best solution is for this.

I believe Gatsby comes with Typescript support out of the box. Are we able to just change the file name from .js to .ts? I have no idea what the repercussions are for that.

I glanced at the Formik repository and it looks like there's a /dist folder that gets created with an index.d.ts file alongside index.js. I then came across this webpage. Could you take a look and see how difficult implementing something like this might be? It looks like there needs to be a build process added to get from javascript to typescript, but the index.d.ts file gets created automatically.

ghost commented 4 years ago

As a workaround to the OP do the following:

This will satisfy the type checker at the import line in your project. If you're adding local web fonts you'll likely need ot do something similar, i.e. declare module "*.woff2"; in a fonts.d.ts.