我写了一些代码来测试typescript如何将ts翻译成js。
const printX = (name: string) => console.log(`hello, ${name}!`)
const tt = () => {
const t1 = 123;
const t2 = 456;
}
我检查了翻译后的js文件,发现它是这样的:
var printX = function (name) { return console.log("hello, ".concat(name, "!")); };
var tt = function () {
var t1 = 123;
var t2 = 456;
};
为什么TypeScript将const关键字翻译成var关键字。
我想知道是否可以强制让ts将const翻译成const。
tsconfig.json
文件,将目标版本设置为ES2015
或更高版本。 - Tobias S.