Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spread types may only be created from object types issue for additionalHeaders in generated requests.ts #706

Closed
fnep opened this issue Jun 21, 2024 · 7 comments 路 Fixed by #708
Labels
bug 馃敟 Something isn't working

Comments

@fnep
Copy link

fnep commented Jun 21, 2024

Description

With the update from version 0.46.3 to 0.47.2, typescript is throwing an error in the generated requests.ts.

I'm not really sure what to do with it. 馃槙

webpack 5.91.0 compiled successfully in 2809 ms
ERROR in ./src/backend/v1/core/request.ts:127:9
TS2698: Spread types may only be created from object types.
    125 |     const headers = Object.entries({
    126 |         Accept: "application/json",
  > 127 |         ...additionalHeaders,
        |         ^^^^^^^^^^^^^^^^^^^^
    128 |         ...options.headers,
    129 |     })
    130 |         .filter(([, value]) => value !== undefined && value !== null)

OpenAPI specification (optional)

No response

Configuration

export default defineConfig({
    input: "openapi.json",
    output: "src/backend/v1",
    services: {
        asClass: true,
    },
});

System information (optional)

No response

@fnep fnep added the bug 馃敟 Something isn't working label Jun 21, 2024
@mrlubos
Copy link
Contributor

mrlubos commented Jun 21, 2024

Does this affect all operations?

@mrlubos
Copy link
Contributor

mrlubos commented Jun 21, 2024

Would you be able to create a minimal reproducible example on StackBlitz?

@fnep
Copy link
Author

fnep commented Jun 21, 2024

Does this affect all operations?

Not sure if I get the question right. It is an error during compile time. Actually, I assume in practice the code will work.

create a minimal reproducible example on StackBlitz

Im new to StackBlitz but i gave it a try. I hope it works for you.

-> https://stackblitz.com/edit/webpack-webpack-js-org-maeyov?file=package.json

I used

  1. npm exec --yes @hey-api/openapi-ts@0.47.2
  2. webpack

to get the error.

@harmen-xb
Copy link

I had the same issue. I think it's related to the typescript version you use. With typescript 4 I get the same error. With typescript ^5.00 it works for me.

@fnep
Copy link
Author

fnep commented Jun 21, 2024

I'm on typescript 5.3.3 in my project, and the StackBlitz example above is on 5.5.2.

@mrlubos
Copy link
Contributor

mrlubos commented Jun 22, 2024

@fnep this will be fixed in the next release, but I suspect it won't solve all your issues. I tried with your example and after fixing this issue, I was getting a weird Webpack error failing to build the services.gen.ts file if I understand it correctly. I believe this might be something to do with the Webpack config itself, but open a new issue if you find out more and think something needs to be fixed in this package.

@fnep
Copy link
Author

fnep commented Jun 24, 2024

Just updated to 0.48.0 and for me, this solved the issue entirely. Thank you! 馃檪

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 馃敟 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants