1. ts
`npm install -g typescript
查看版本:tsc -v`
2. zsh: command not found: tsc npm install -g typescript
3. 报错 修改完成 关闭配置文件并且重新运行文件
File 'test.js' is a JavaScript file. Did you mean to enable the 'allowJs' option? The file is in t
{
"compilerOptions": {
"allowJs": true,
// 其他配置项...
}
// 其他配置项...
}
4. 报错 npm install@types/node -D
重启项目
Subsequent variable declarations must have the same type. Variable 'AbortSignal' must be of type '{ new (): AbortSignal; prototype: AbortSignal; abort(reason?: any): AbortSignal; timeout(milliseconds: number): AbortSignal; }', but here has type '{ new (): AbortSignal; prototype: AbortSignal; }'.
![image.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/8ad7757fbb054be3816567ee8d99268d~tplv-k3u1fbpfcp-jj-mark:0:0:0:0:q75.image#?w=1640&h=590&s=572162&e=png&b=202020)
72 declare var AbortSignal: {
~~~~~~~~~~~
../../../../../../usr/local/lib/node_modules/typescript/lib/lib.dom.d.ts:2337:13
2337 declare var AbortSignal: {
~~~~~~~~~~~
'AbortSignal' was also declared here.
Found 1 error in node_modules/@types/node/globals.d.ts:72
5. ts文件运行
tsc test.ts
会生成一个js文件 .ts => .js => 浏览器执行环境
问题:ts的类型检测和语法检测在什么时间? 在编译时
6. # 在引入React时为什么会出现“cannotuseimportstatementoutsideamodule”的错误
npm install --save-dev webpack webpack-cli babel-loader @babel/core @babel/preset-env