microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.08k stars 12.37k forks source link

Request: 'target: ES2018' should inclide libraries without an additional 'lib: ['es2015'] #27479

Closed mikemaccana closed 1 month ago

mikemaccana commented 5 years ago

In tsconfig:

"target": "ES2018"

Will produce a whole bunch of warnings when encountering ES2018 code. For example using Promises requires adding:

"lib": ["es2015"]

Or installing additional type libs. It would be better if typescript just produced ES2018 when I targeted ES2018 without needing additional config? If I need additional type libs that aren't included by default, tsc should add them.

mikemaccana commented 5 years ago

Just I note that I have no idea what I'm doing, all I know is that:

RyanCavanaugh commented 5 years ago

Trying to reproduce this problem based on what you've told me:

D:\Throwaway\test>type tsconfig.json
{
  "compilerOptions": {
    "target": "es2018"
 }
}
D:\Throwaway\test>type a.ts
var x: Promise<string>;

D:\Throwaway\test>tsc

D:\Throwaway\test>
mohsen1 commented 5 years ago

Are you using async iterables?

msbit commented 4 years ago

I can't speak for @mikemaccana's specific case, however I thought that I was experiencing the same issue, but it was actually a side-effect of https://github.com/microsoft/TypeScript/issues/5858 in which providing the file name on the command line causes tsc to ignore the tsconfig.json file:

cat << EOF > tsconfig.json
{
  "compilerOptions": {
    "target": "es2018"
 }
}
EOF

cat << EOF > a.ts
var x = async () => {};
EOF

tsc
# no output

tsc a.ts
error TS2468: Cannot find global value 'Promise'.

a.ts:1:9 - error TS2705: An async function or method in ES5/ES3 requires the 'Promise' constructor.  Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your `--lib` option.

1 var x = async () => {};
          ~~~~~~~~~~~~~~

Found 2 errors.