In consts.ts i have
const s1: string = 'test';
I compile it with tsc consts.ts and then in consts.js it became
var s1 = 'test';
Why?
CodePudding user response:
TypeScript compiles to ECMAScript 3 code unless you specify otherwise [doc link], and ECMAScript didn't introduce const
until version 6.
CodePudding user response:
So it seems that you don't have any typescript configuration for your project. You have to run
npx tsc --init
and then you will be able to change the target value for compiler option there
{
"compilerOptions": {
"target": "es2017"
}
}