[REQ] Ability to configure target javascript version for typescript compiler in typescript generators
Created by: cghislai
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