I worte some code to test typescript how to translate ts -> js.

const printX = (name: string) => console.log(`hello, ${name}!`)
const tt = () => {
 const t1 = 123;
const t2 = 456;


I checked the translated js file and it was,

var printX = function (name) { return console.log("hello, ".concat(name, "!")); };
var tt = function () {
    var t1 = 123;
    var t2 = 456;

Why Typescript translate from const keyword to var keyword.

I'm wondering if I can make ts translate force const to const.


Set the target in your tsconfig to something above ES5, and then ES6 syntax (such as const) will be preserved.

Modern browsers support all ES6 features, so ES6 is a good choice. You might choose to set a lower target if your code is deployed to older environments, or a higher target if your code is guaranteed to run in newer environments.

The target setting changes which JS features are downleveled and which are left intact. For example, an arrow function () => this will be turned into an equivalent function expression if target is ES5 or lower.


函数类型映射和参数类型之间的Typescript 匹配

REST - 强类型模型

在 TypeScript 4.7.3 中使用类型谓词不会返回正确的类型

如何使用 TypeScript 动态调用对象上的方法?


在 TypeScript 中组合并集和交集类型时的参数类型解析

React-native & typescript: 组件,属性“children”在类型“IntrinsAttributes &...”上不存在



如何使用 *ngFor 显示 json 对象

错误 TS4053:来自导出类的公共方法的返回类型具有或正在使用名称“Observable”


SyntaxError:意外的令牌导入 TypeORM 实体


在 cshtml 文件中使用 TypeScript

NullInjectorError:没有 JwtHelperService 的提供者

如何使用 TypeScript 在 React 组件类上声明 defaultProps?

如何更改Angularmaterial日期 Select 器格式

为什么 push 显示类型为“any[]”的参数不可分配给类型为“never”的参数错误?

TypeScript 判断空字符串