TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

Specialized error message for setting `lib` or `target` to a future ES version

Open uhyo opened this issue 1 year ago • 1 comments

Fixes #60050

This PR improves the diagnostic message for unsupported lib or target values by emitting a specialized message when the specified value looks like a future ES version.

I altered the originally suggested message a bit because printing a concrete TypeScript version in the error message felt a skosh unusual to me, instead using the phrase this version of TypeScript. Of course I'm open to any change suggested by reviewers.

Example

tsconfig.json

{
  "compilerOptions": {
    "target": "es2099",
    "lib": ["es2098", "dom"],
  },
  "include": ["src"]
}

🏠 Current Behavior

tsconfig.json:3:15 - error TS6046: Argument for '--target' option must be: 'es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext'.

3     "target": "es2099",
                ~~~~~~~~

tsconfig.json:4:13 - error TS6046: Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'es2021', 'es2022', 'es2023', 'esnext', 'dom', 'dom.iterable', 'dom.asynciterable', 'webworker', 'webworker.importscripts', 'webworker.iterable', 'webworker.asynciterable', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2016.intl', 'es2017.date', 'es2017.object', 'es2017.sharedmemory', 'es2017.string', 'es2017.intl', 'es2017.typedarrays', 'es2018.asyncgenerator', 'es2018.asynciterable', 'es2018.intl', 'es2018.promise', 'es2018.regexp', 'es2019.array', 'es2019.object', 'es2019.string', 'es2019.symbol', 'es2019.intl', 'es2020.bigint', 'es2020.date', 'es2020.promise', 'es2020.sharedmemory', 'es2020.string', 'es2020.symbol.wellknown', 'es2020.intl', 'es2020.number', 'es2021.promise', 'es2021.string', 'es2021.weakref', 'es2021.intl', 'es2022.array', 'es2022.error', 'es2022.intl', 'es2022.object', 'es2022.sharedmemory', 'es2022.string', 'es2022.regexp', 'es2023.array', 'es2023.collection', 'es2023.intl', 'esnext.array', 'esnext.collection', 'esnext.symbol', 'esnext.asynciterable', 'esnext.intl', 'esnext.disposable', 'esnext.bigint', 'esnext.string', 'esnext.promise', 'esnext.weakref', 'esnext.decorators', 'esnext.object', 'esnext.regexp', 'esnext.iterator', 'decorators', 'decorators.legacy'.

4     "lib": ["es2098", "dom"],
              ~~~~~~~~

🌟 New Behavior

tsconfig.json:3:15 - error TS6284: Argument 'es2099' for '--target' option is a year not yet supported by this version of TypeScript.

3     "target": "es2099",
                ~~~~~~~~

tsconfig.json:4:13 - error TS6284: Argument 'es2098' for '--lib' option is a year not yet supported by this version of TypeScript.

4     "lib": ["es2098", "dom"],
              ~~~~~~~~

uhyo avatar Oct 14 '24 06:10 uhyo

The TypeScript team hasn't accepted the linked issue #60050. If you can get it accepted, this PR will have a better chance of being reviewed.

typescript-bot avatar Oct 14 '24 06:10 typescript-bot