openapi-react-query-codegen icon indicating copy to clipboard operation
openapi-react-query-codegen copied to clipboard

"error TS6133: 'queryKey' is declared but its value is never read" from queries.ts and suspense.ts

Open Etsija opened this issue 1 year ago • 4 comments

Describe the bug Files queries/queries.ts and queries/suspense.ts generate TS errors from queryKey being declared but its value never read, resulting in error TS6133 when building a project with the API.

OpenAPI JSON causing the bug api.json

Expected behavior Either don't generate unused parameters, or auto-insert

// @ts-nocheck

to generated files which may declare unused variables.

  • OS: Ubuntu 22.04
  • Version 1.3.0

Etsija avatar May 13 '24 11:05 Etsija

Does this report, just like mine, need to go to upstream https://github.com/hey-api/openapi-ts as well?

sschuberth avatar May 13 '24 11:05 sschuberth

I'd like an answer to the question above, as we need a fix to this issue, and need to know whether we should create a ticket upstream.

Etsija avatar May 15 '24 03:05 Etsija

This is a bug. queryKey should always be used. The issue is that when there are no parameters for a request, then the queryKey is not used in the hook; this is incorrect. We should be using the provided queryKey if it is provided.

A work-around until a fix is implemented is to add the // @ts-nocheck to the files or to add the following properties to your tsconfig

{
  ...
  "noUnusedParameters": false,
  "noUnusedLocals": false
  ...
}

seriouslag avatar May 15 '24 06:05 seriouslag

Thanks for the reply, I will be following this issue to see when a proper fix is implemented so we can remove our workarounds for it.

Etsija avatar May 15 '24 06:05 Etsija