js模块怎么定义的
ts和es2015一样,任何一个文件包括顶层的import或者export就会被认为是一个模块。一个文件没有顶层的import或者export声明,它的内容就是在全局作用域。
转为模块
export {};
import type
import type { Cat, Dog } from "./animal.js";
export type Animals = Cat | Dog;
Inline type imports
ts 4.5版本以上
import { createCatName, type Cat, type Dog } from "./animal.js";
这样可以使非ts编译器,比如像babel,swc,esbuild安全的移除导入的类型。
Module Resolution
- Classic
- Node
- node16 或者 nodenext
输出选项
target
生成代码的兼容性
module
决定模块怎么联系。值有:amd, umd, es6, esnext, node16等