wsdl-tsclient icon indicating copy to clipboard operation
wsdl-tsclient copied to clipboard

Type re-exporting problem with Next.js

Open dmitryk-sfx opened this issue 3 years ago • 9 comments

First of all big thanks for great library!

My problem is: current types re-exporting in index.ts file break Next.js build because framework strict isolatedModules to be enabled. This issue can be solved with rewriting exports manually after client generation, but will be better if this will be solved on library level.

dmitryk-sfx avatar Feb 18 '22 12:02 dmitryk-sfx

Hi @dmitryk-sfx ,

Could you please explain it little bit more? What kind of result are you expecting?

Thanks!

dderevjanik avatar Apr 16 '22 16:04 dderevjanik

I have a problem that sounds like this -> if a Type references itself an import to itself is added to the Type file.

import { ArcImageInfo } from "./ArcImageInfo";

export interface ArcImageInfo {
    /** docReference[] */
    docReference?: Array<ArcImageInfo>;
}

ok - that specific issue seems to have been solved here: https://github.com/dderevjanik/wsdl-tsclient/pull/39

wodka avatar Apr 24 '22 15:04 wodka

Hi @dmitryk-sfx ,

Could you please explain it little bit more? What kind of result are you expecting?

Thanks!

Sorry for delay.

Currently library re-export types from definitions, services, ports and client.ts in index.ts with export { SomeType } from and create a problem in case when tsconfig have isolatedModules: true flag because in this case export type { SomeType } from syntax required for types re-exporting.

This was error from TS Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.

This is can be fixed with rewriting types exports after client generation, but I think this should be fixed on library side. My short script for rewrite exports:

// Temporary solution for types re-export problem for --isolatedModules: true
const indexFile = readFileSync(
  `${generatedFolder}/${service.toLowerCase()}/index.ts`,
  'utf8'
)
const formattedIndexFile = indexFile
  .replace(/export { (?!createClientAsync)/g, 'export type { ')

writeFileSync(
  `${generatedFolder}/${service.toLowerCase()}/index.ts`,
  formattedIndexFile
)

dmitryk-sfx avatar Apr 25 '22 07:04 dmitryk-sfx

I'm not ts-morph user, but looks installation folder tsconfig.json didn't respected. https://ts-morph.com/setup/#tsconfigjson I think this can be fixed in combination of two features on library side:

  1. Automatically detect installation folder tsconfig.json file and pass it to ts-morph project setup.
  2. Allow passing user location of tsconfig.json file in generateClient or CLI that will be passed directly to ts-morph project setup. This will help close possible related issues when config located not in the project root or name was changed, for example wsdl-tsclient.tsconfig.json.

dmitryk-sfx avatar Apr 25 '22 08:04 dmitryk-sfx

@dmitryk-sfx Do you think this could be solved by simply adding export type { Something } from "./something" to index.ts file? I'm not familiar with isolatedModules.

dderevjanik avatar Apr 25 '22 14:04 dderevjanik

Right.

dmitryk-sfx avatar May 01 '22 15:05 dmitryk-sfx

Any activity on this? Would be great to be able to use this in NextJS, as it requires to have isolatedModules: true.

Edit: I'm happy to test any solutions or provide a reproduction repo if that helps.

n1kio avatar Aug 11 '22 11:08 n1kio

Hello, Any update on this issue? It makes the compilation not working unless you fix the types manually, which would be overridden the next time you try to generate the client

dstoyanoff avatar Jan 29 '23 13:01 dstoyanoff