Closed mikemaccana closed 1 month ago
Just I note that I have no idea what I'm doing, all I know is that:
I just asked TypeScript to produce ES2018
I don't understand why I have to do this again
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>
Are you using async iterables?
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.
In tsconfig:
Will produce a whole bunch of warnings when encountering ES2018 code. For example using Promises requires adding:
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.