hey-api / openapi-ts

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos
https://heyapi.dev
Other
1.4k stars 106 forks source link

ESLint no-invalid-void-type error in services.gen.ts #1103

Closed lukaskoeller closed 2 weeks ago

lukaskoeller commented 1 month ago

Description

Actual

In the services.gen.ts there are void is only valid as a return type or generic type argument.eslint[@typescript-eslint/no-invalid-void-type](https://typescript-eslint.io/rules/no-invalid-void-type) errors appearing.

Expected

The eslint page suggests to use undefined instead.

That would mean that these appearances would change as follows:

export const postAuthResetPassword = <ThrowOnError extends boolean = false>(
  options: Options<PostAuthResetPasswordData, ThrowOnError>,
) => {
-  return (options.client ?? client).post<void, unknown, ThrowOnError>({
+  return (options.client ?? client).post<undefined, unknown, ThrowOnError>({
    ...options,
    url: "/auth/reset_password",
  });
};

Reproducible example or configuration

https://stackblitz.com/edit/hey-api-client-fetch-example-nppfy7?file=src%2Fclient%2Fservices.gen.ts

Then run npm run lint. Quite some issues will appear, but some will be like:

/home/projects/hey-api-client-fetch-example/src/client/services.gen.ts
…
153:57  error  void is only valid as a return type or generic type argument

OpenAPI specification (optional)

Any OpenAPI endpoint that does return nothing basically.

System information (optional)

Only thing important to mention here, is a more strict eslint config:

extends: [
    'eslint:recommended',
    'plugin:@typescript-eslint/strict-type-checked',
    'plugin:@typescript-eslint/stylistic-type-checked',
  ],
parserOptions: {
    ecmaVersion: "latest",
    sourceType: "module",
    project: ["./tsconfig.json", "./tsconfig.node.json"],
    tsconfigRootDir: __dirname,
  },

These were added/edited to the base stackblitz example. It is the recommended production setup by the vite react-ts template (see README)

stackblitz[bot] commented 1 month ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

mrlubos commented 1 month ago

This will be addressed as part of the parser release. Thank you for reporting!

mrlubos commented 2 weeks ago

@lukaskoeller this is fixed in the experimental parser. For more information about it, see the release page https://github.com/hey-api/openapi-ts/releases/tag/%40hey-api%2Fopenapi-ts%400.54.3

Experimental parser is currently opt-in to gather feedback before making it widely available. Please let me know if you run into any issues with it!