NJsonSchema icon indicating copy to clipboard operation
NJsonSchema copied to clipboard

Typescript: order of class / base class

Open jochenjonc opened this issue 5 years ago • 7 comments

With the latest version of NSwag v12.3.0.0 and NJsonSchema v9.14.1.0 I have an issue that not my abstract class is positioned lower than a class that extends it in TypeScript.

error TS2449: Class 'Calendar' used before its declaration

jochenjonc avatar May 21 '19 12:05 jochenjonc

See https://github.com/RicoSuter/NSwag/issues/2184#

RicoSuter avatar May 21 '19 21:05 RicoSuter

I am still struggling with these problem. (NSwag v13.1.3)

I have a Base DTO class: BaseEntity and I have some DTOs with name eg. Grape, Melon ... (come later in ABC) which extend BaseEntity.

Typescript generation works well until I add a DTO with Name starting with A (before B in ABC)

So after I add these block to my extensions ts:

class Apple extends generated.Apple {
   // some customizations ...
}

I get the following: error TS2449: Class 'BaseEntity' used before its declaration.

How can I solve it?

kollerdroid avatar Nov 05 '19 15:11 kollerdroid

I run into the same issue, can you give us some update about that?

benceczeili avatar Apr 27 '20 11:04 benceczeili

I'm also seeing this behaviour, I've tried versions 13.5.0 and 13.4.2. The base class is put at the bottom of the file. I followed the guide from here:

https://github.com/RicoSuter/NSwag/wiki/TypeScriptClientGenerator#inject-an-authorization-header

connelhooley avatar May 11 '20 16:05 connelhooley

Is this still an issue with the latest version? I think we improved the ordering...

RicoSuter avatar Sep 29 '20 13:09 RicoSuter

I have run into this problem today - trying to write a base class for all clients, options:

"clientBaseClass": "ClientBase",
"extensionCode": "clientbase.ts",

where clientbase.ts looks like:

export class ClientBase {
    protected transformOptions = (options: AxiosRequestConfig): Promise<AxiosRequestConfig> => {
        options.headers = {
            ...options.headers,
            'SOME-TOKEN': 'SomeToken',
        };
        return Promise.resolve(options);
    };
  }

resulting in:

image

using: NSwag toolchain v13.10.1.0 (NJsonSchema v10.3.3.0 (Newtonsoft.Json v12.0.0.0)) (http://NSwag.org)

patrickklaeren avatar Jan 24 '21 12:01 patrickklaeren

It still happens for us with version 13.17.0 :(

Cyclodex avatar Sep 30 '22 15:09 Cyclodex