OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.87k stars 6.59k forks source link

[BUG] [Typescript] Generic type 'URLParse<Query>' requires 1 type argument(s). #12625

Open charlax opened 2 years ago

charlax commented 2 years ago

Bug Report Checklist

Description

Contrary to v5.4.0, the generate http/http.ts does not include the @ts-ignore comment and as such fail type checking:

./node_modules/.../http/http.ts:44:18
Type error: Generic type 'URLParse<Query>' requires 1 type argument(s).

  42 |     private headers: { [key: string]: string } = {};
  43 |     private body: RequestBody = undefined;
> 44 |     private url: URLParse;
     |                  ^
  45 |
  46 |     /**
  47 |      * Creates the request context using a http method and request resource url
info  - Checking validity of types .%

(tested with url-parse types 1.4.8. I get other errors with 1.4.4)

openapi-generator version

v6.0.0

OpenAPI declaration file content or url

N/A

Generation Details

N/A

Steps to reproduce
Related issues/PRs

Introduced in https://github.com/OpenAPITools/openapi-generator/pull/11465

Suggest a fix

Add back the // @ts-ignore?

carusooo commented 2 years ago

Manually adding the //@ts-ignore didn't solve the issue for me.

I ended up changing the type of the URLParse in the RequestContext to URLParse<Record<string, string | undefined>>; so that it looks like this

/**
 * Represents an HTTP request context
 */
export class RequestContext {
    private headers: { [key: string]: string } = {};
    private body: RequestBody = undefined;
    private url: URLParse<Record<string, string | undefined>>;
thenbe commented 2 years ago

Fixed this by using the pinned version of @types/url-parse as defined in the generated package.json. At time of writing, this is "@types/url-parse": "1.4.4".