Openapi-generator: [BUG][Typescript-axios] Typescript 4.0.x: the operand of a 'delete' operator must be optional

Created on 24 Aug 2020  路  10Comments  路  Source: OpenAPITools/openapi-generator

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] What's the version of OpenAPI Generator used?
  • [x] Have you search for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Bounty to sponsor the fix (example)
Description

Upgrading to TypeScript 4.0.x now causes issues within the AxiosParamCreator function. It will complain about:

generated/api.ts:149:20 - error TS2790: The operand of a 'delete' operator must be optional.

Further reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-0/#operands-for-delete-must-be-optional

openapi-generator version

v5.0.0-beta

OpenAPI declaration file content or url

https://github.com/sebas2day/typescript-axios-error

Generation Details

typescript-axios

Steps to reproduce
  1. wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.0.0-beta/openapi-generator-cli-5.0.0-beta.jar
  2. yarn
  3. java -jar openapi-generator-cli-5.0.0-beta.jar generate -i spec.yaml -g typescript-axios -o generated
  4. yarn tsc -b -f

Outcome:

generated/api.ts:71:20 - error TS2790: The operand of a 'delete' operator must be optional.

71             delete localVarUrlObj.search;
                      ~~~~~~~~~~~~~~~~~~~~~


Found 1 error.

error Command failed with exit code 1.
Related issues/PRs

NA

Suggest a fix

Instead of using delete it would be better to assign it with null.

Bug

Most helpful comment

@luixal this should be fixed in 5.0.0 beta

All 10 comments

@sebas2day would you like to fix this?

@macjohnny Yes, I'll make a PR for it

Ah looks like this issue implicitly got fixed by this PR #6960 but is not released yet :)

There's still some compiling issues however:

generated/api.ts:56:40 - error TS2304: Cannot find name 'URL'.

56             const localVarUrlObj = new URL(localVarPath, 'https://example.com');
                                          ~~~

generated/api.ts:69:31 - error TS2304: Cannot find name 'URLSearchParams'.

69             const query = new URLSearchParams(localVarUrlObj.search);
                                 ~~~~~~~~~~~~~~~

generated/api.ts:76:42 - error TS2304: Cannot find name 'URLSearchParams'.

76             localVarUrlObj.search = (new URLSearchParams(query)).toString();
                                            ~~~~~~~~~~~~~~~


Found 3 errors.

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I'll make a fix

@sebas2day the URL class should be available in the browser as well as in node environments: https://nodejs.org/api/url.html#url_new_url_input_base

@macjohnny Yes, but the compilation will break when you don't have the "lib": ["dom"] included in your tsconfig like within the tests. For my use case I'm working in a node-only environment where I don't want to include this lib.

@sebas2day
I think that is a typescript issue. (https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34960)

Just hit this issue (the The operand of a 'delete' operator must be optional one) running version 4.3.1.

Any workaround?

Thanks!

@luixal this should be fixed in 5.0.0 beta

Just add global
declare module 'url' { interface Url { search: string | null | undefined; } }

Was this page helpful?
0 / 5 - 0 ratings