OpenAPITools / OpenAPITools/openapi-generator

[REQ] Ability to configure target javascript version for typescript compiler in typescript generators

Open
#10,974 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

When porting the typescript-angular client generator to angular 13, I wanted to update the versions in the the generated tsconfig.json.
The file is currently hardcoded to es6 or es5 depending on a 'supportES6' common to all typescript clients.

It is used to generate the tsconfig. The following snippet has been copy/pasted to most generator templates:

 "target": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}es5{{/supportsES6}}",
 "module": "{{#supportsES6}}es6{{/supportsES6}}{{^supportsES6}}commonjs{{/supportsES6}}",
{{^supportsES6}}
    "lib": [
      "es6",
      "dom"
    ],
    {{/supportsES6}}

And in some template, a corejs dependency is added for non-es6 targets.

Concerning the target javascript platform:

  • Each generators may support a subset of javascript target platforms
  • An end-user may want to specify a target platform, and take care of providing polyfills

Concerning the module configuration:

  • An end user may want to overrides the gerenated module format depending on how the module is impored

Concerning the addition of a core-js dependency:

  • This is polyfill library, to provide runtime librairies to the javascript platform, and should not be required for typescript compilation.
  • It is not imported in the generated typescript-aurelia sample client, so the dependency sees unneeded.

Concerning the lib to include in typescript compilation:

  • This should be derived from the target platform. eg when targeting es2017 libs up to es2017 should be provided to the compiler.
  • By default, typescript includes the librairies of the target specified, so this option could probably be ignored.

Describe the solution you'd like

A more future-proof way to configure and handle javascript targets.

Im not sure Ive considered all options so this issue is more to sparkle discussion and query a consensus.

In my opinion we should be left with

  • each generator defaulting a target and module` in their tsconfig.json
  • no generator specifying additional lib unless required
  • one tsModule option for the enduser to override
  • one tsTarget option for the enduser to override.

Describe alternatives you've considered

Adding a supportsES2020 config flag

Additional context

https://github.com/OpenAPITools/openapi-generator/pull/10877

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 by reviewing the TypeScript generator templates and the linked pull request #10877, focusing on how generated tsconfig.json files use supportsES6, target, module, lib, and core-js. Done means reaching consensus on the configuration options and defaults, then applying and validating that approach across the affected TypeScript generators.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.