Search code examples
typescriptconstants

Why Typesript compiler change a const into a var?


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?


Solution

  • 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"
      }
    }