-
-
Notifications
You must be signed in to change notification settings - Fork 418
Description
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 .