-
-
Notifications
You must be signed in to change notification settings - Fork 395
Type errors when compiling with the --axios option #301
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Heres the relevant lines in the outputted file starting from line 470:
|
I have the same issue and worked around it by adding // @ts-ignore before those 3 lines. |
I've done that for now but its not really a sustainable option if I end up sticking with my current project. |
TLDR: stick with [email protected] for now I guess. There have been changes to typing in [email protected] and 0.23.0 This construction is no longer possible (not sure it had any effect in the first place TBH).
As the
Would this be desired effect or was the intention for the changes in the header to be applied only for the current request? |
Use the swagger-typescript-api-nextgen fork, it solves this problem. The package is present in the npm. |
Uh oh!
There was an error while loading. Please reload this page.
I get these errors when running tsc after generating the api with the axios option.
The normal fetch option works fine however I am targeting node and node-fetch doesn't want to work with it.
The compilation errors I get are:
src/api/data-portal.ts:471:7 - error TS2532: Object is possibly 'undefined'.
471 requestParams.headers.common = { Accept: "/" };
~~~~~~~~~~~~~~~~~~~~~
src/api/data-portal.ts:471:7 - error TS2322: Type '{ Accept: string; }' is not assignable to type 's
tring'.
471 requestParams.headers.common = { Accept: "/" };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/data-portal.ts:472:7 - error TS2532: Object is possibly 'undefined'.
472 requestParams.headers.post = {};
~~~~~~~~~~~~~~~~~~~~~
src/api/data-portal.ts:472:7 - error TS2322: Type '{}' is not assignable to type 'string'.
472 requestParams.headers.post = {};
~~~~~~~~~~~~~~~~~~~~~~~~~~
src/api/data-portal.ts:473:7 - error TS2532: Object is possibly 'undefined'.
473 requestParams.headers.put = {};
~~~~~~~~~~~~~~~~~~~~~
src/api/data-portal.ts:473:7 - error TS2322: Type '{}' is not assignable to type 'string'.
473 requestParams.headers.put = {};
~~~~~~~~~~~~~~~~~~~~~~~~~
Found 6 errors.
I generate the api successfully with the command:
npx swagger-typescript-api --path src/un-data-portal.json -o ./src/api/ -n data-portal.ts --axios
And then run:
npx tsc
If there is no easy fix for this does anyone know how to get node-fetch working with the default version instead?
In case it matters I'm using the latest versions of axios and swagger-typescript-api and using node v16.8.0 with typescript Version 4.4.3 .
The text was updated successfully, but these errors were encountered: