shopify-app-template-node icon indicating copy to clipboard operation
shopify-app-template-node copied to clipboard

Type 'ParsedQs' cannot be used as an index type.

Open leithden opened this issue 3 years ago • 3 comments

Issue summary

image

I am getting an error in the index.js file, I am not sure why getting this error

Expected behavior

I just install the embedded app code from Shopify cli, but its throwing this error in index.js

image

Specifications

  • Browser: brave
  • Device:
  • Operating System: Windows 10

leithden avatar Jun 20 '22 10:06 leithden

Hey @remyoswalt! I've faced the same issue, however the error is coming for js files from ts setup which is weird. The workaround with js files for this is to wrap shop with String(shop) and req.query with ~~JSON.parse(JSON.stringify(req.query))~~ Object(req.query).

If you'd like to try the same template with TS setup, you can checkout shopify-app-template-typescript that I maintain and this error is avoided more in TS way -- https://github.com/kanzitelli/shopify-app-template-typescript/blob/main/server/index.ts#L98

kanzitelli avatar Jun 20 '22 19:06 kanzitelli

@kanzitelli, Thank you so much for helping, is there not any way to solve this error within js files? I am not that much familiar with typescript and personally want to use javascript for the whole project.

leithden avatar Jun 21 '22 02:06 leithden

@remyoswalt sure, you can try these lines of code for js:

if (app.get("active-shopify-shops")[String(shop)] === undefined && shop) {
  res.redirect(`/auth?${new URLSearchParams(Object(req.query)).toString()}`);
} else {
  next();
}

Basically, you just force wrap them with String() and Object(). The errors should disappear.

kanzitelli avatar Jun 21 '22 09:06 kanzitelli

This issue is stale because it has been open for 90 days with no activity. It will be closed if no further action occurs in 14 days.

github-actions[bot] avatar Sep 28 '22 02:09 github-actions[bot]

We are closing this issue because it has been inactive for a few months. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on since it was submitted, then it seems other issues have taken priority.

If you still encounter this issue with the latest stable version, please reopen using the issue template. You can also contribute directly by submitting a pull request– see the CONTRIBUTING.md file for guidelines

Thank you!

github-actions[bot] avatar Oct 13 '22 02:10 github-actions[bot]