swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

typescript reports errors with FormData since 13.0.10

Open jeremyriverain opened this issue 1 year ago • 5 comments

I'm experiencing TypeScript errors that come from the generated http-client.ts.

Here are the errors:

Capture d’écran du 2024-07-01 12-26-26

My build passes with version 13.0.10 of swagger-typescript-api but not with version 13.0.11.

By comparing the 2 generated files, here are the differences I obtain:

Capture d’écran du 2024-07-01 12-23-06

The file on the left is the one generated by swagger-typescript-api version 13.0.11. It has TypeScript errors.

The file on the right does not have TypeScript error.

My project uses version 5.2 of typescript.

I think the bug is introduced by this commit: https://github.com/acacode/swagger-typescript-api/commit/0d80f8e6ea5a2420745841f8b9eb95faae0b4ffc

jeremyriverain avatar Jul 01 '24 10:07 jeremyriverain

Provide specific reproducible example.

smorimoto avatar Jul 01 '24 13:07 smorimoto

Hey, I'm wondering what the intention of this change is. If I need to pass in an instance of FormData as the request body, why do I need the formatter then? It just recreates the FormData instance again (and possibly loses information, because it e.g. does not support he third parameter of FormData.prototype.append). For me the main use case of this formatter was, that I can pass in a plain object, that is transformed to a FormData instance. This is broken (by-design?) now, but imho shouldn't have happened in a patch release.

am-burban avatar Jul 01 '24 15:07 am-burban

Hello @jeremyriverain ,

I guess you have to add "dom.iterable" into your tsconfig:

"compilerOptions": { "lib": ["esNext", "dom", "dom.iterable"],

philippone avatar Jul 02 '24 10:07 philippone

Hi I second this bug. After the update the autogenerated code is generating in the http-client new code with Array.from instead of Object.keys. This then brings the same error as Jeremy.

I had already in my compilerOptions the "dom.iterable"

svarion1 avatar Jul 04 '24 16:07 svarion1

Same issue occurs with 13.0.12.

payammeyer avatar Jul 05 '24 17:07 payammeyer

I renamed the file from http-client.ts to api.d.ts and the error disappeared

motionrus avatar Jul 15 '24 05:07 motionrus

I am wondering - will it just stay as it is? It is a breaking change in a patch version, right?

AlexanderShabalin avatar Aug 01 '24 07:08 AlexanderShabalin

I don't think it was a breaking change, it was really just a fix. If someone could share a minimal reproduction example, I will take a look at it and provide some pointers.

smorimoto avatar Aug 01 '24 14:08 smorimoto

I've created a reproducible example here: benvd/swagger-typescript-api-814.

benvd avatar Aug 02 '24 08:08 benvd

@benvd Indeed! It was definitely a bug! I will revert the PR and release it as 13.0.16.

smorimoto avatar Aug 02 '24 17:08 smorimoto

https://github.com/acacode/swagger-typescript-api/releases/tag/13.0.16

smorimoto avatar Aug 02 '24 17:08 smorimoto