Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type re-exporting problem with Next.js #33

Open
dmitryk-sfx opened this issue Feb 18, 2022 · 8 comments
Open

Type re-exporting problem with Next.js #33

dmitryk-sfx opened this issue Feb 18, 2022 · 8 comments

Comments

@dmitryk-sfx
Copy link

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.

@dderevjanik
Copy link
Owner

Hi @dmitryk-sfx ,

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

Thanks!

@wodka
Copy link

wodka commented Apr 24, 2022

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: #39

@dmitryk-sfx
Copy link
Author

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
Copy link
Author

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.

@dderevjanik
Copy link
Owner

@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.

@dmitryk-sfx
Copy link
Author

Right.

@n1kio
Copy link

n1kio commented Aug 11, 2022

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.

@dstoyanoff
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants