Q
Q
Quintis2021-04-20 09:51:33
typescript
Quintis, 2021-04-20 09:51:33

How to change the standard for Typescript?

Installed npm install typescript in the folder. The folder contains the following files:
1) test.ts

const str:string = "Hello TS !"
console.log(str)

2) test.js
var str = "Hello TS !";
console.log(str);

3) tsconfig.json
{
    "compilerOptions": {
      "target": "ES2020",
      "module": "commonjs",
      "strict": true,
      "esModuleInterop": true,
      "skipLibCheck": true,
      "forceConsistentCasingInFileNames": true
    },
    "$schema": "https://json.schemastore.org/tsconfig",
    "display": "Recommended"
  }

4) node_modules
test.js was compiled with test.ts via command "tsc test.ts" The
question is, why is str variable defined via var ? How to make it so that it would be const

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lynn "Coffee Man", 2021-04-20
@Quintis

Compile a project, not a single file.
When you call tsc test.ts, TS does not read tsconfig.json, but uses the default settings.
So just call tsc.
Or explicitly specify options on the command linetsc --target ES2020 test.ts

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question