TypeScript 与 es6 写法的区别

时间:2023-03-09 01:45:45
TypeScript 与 es6 写法的区别
  • import 方式

    ts 默认对于 commonjs 的模块是这样加载的:import * as React from 'react';

    es6:import React from 'react';

    不想改变 es6 的写法,可以使用 ts 提供的一个编译参数 allowSyntheticDefaultImports
{
"allowSyntheticDefaultImports": true,
"module": "esnext",
"moduleResolution": "node"
}