OpenAPITools / OpenAPITools/openapi-generator

[BUG] [typescript] not compatible with --isolatedModules

Open
#6,805 6 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

Using the new TypeScript generator from #6341

The generated code is not compatible with --isolatedModules, which is required by popular setups such as create-react-app.

openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url

https://github.com/bard/repro-openapi-generator-typescript-isolated-modules/blob/master/example.yaml

Command line used for generation

OPENAPI_GENERATOR_VERSION=5.0.0-SNAPSHOT /tmp/openapi-generator-cli.sh generate -g typescript -i example.yaml -o ./src/api

Steps to reproduce
  1. git clone https://github.com/bard/repro-openapi-generator-typescript-isolated-modules/blob/master/example.yaml
  2. OPENAPI_GENERATOR_VERSION=5.0.0-SNAPSHOT /tmp/openapi-generator-cli.sh generate -g typescript -i example.yaml -o ./src/api
  3. yarn && yarn start
Failed to compile.

/tmp/repro-openapi-generator-typescript-isolated-modules/src/api/index.ts
TypeScript error in /tmp/repro-openapi-generator-typescript-isolated-modules/src/api/index.ts(4,31):
Cannot re-export a type when the '--isolatedModules' flag is provided.  TS1205

    2 | export * from "./auth/auth";
    3 | export * from "./models/all";
  > 4 | export { createConfiguration, Configuration } from "./configuration"
      |                               ^
    5 | export * from "./apis/exception";
    6 | export * from "./servers";
    7 | 
Related issues/PRs

https://github.com/facebook/create-react-app/issues/6054

Suggest a fix

Possible workaround is to export * from index.ts:

  export * from "./http/http";
  export * from "./auth/auth";
  export * from "./models/all";
- export { createConfiguration, Configuration } from "./configuration"
+ export * from "./configuration"
  export * from "./apis/exception";
  export * from "./servers";

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the generated src/api/index.ts shown in the report and reproduce the failure using the provided OpenAPI declaration, generator command, and yarn start steps. Trace that output back to the TypeScript generator templates or entry points, then verify that regenerated code compiles with --isolatedModules without the TS1205 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.