7nohe / openapi-react-query-codegen

OpenAPI React Query Codegen is a code generator for creating React Query (also known as TanStack Query) hooks based on your OpenAPI schema.
https://openapi-react-query-codegen.vercel.app
MIT License
298 stars 30 forks source link

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

Closed Etsija closed 6 months ago

Etsija commented 6 months ago

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.

sschuberth commented 6 months ago

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

Etsija commented 6 months ago

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.

seriouslag commented 6 months ago

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
  ...
}
Etsija commented 6 months ago

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.