ts

ts的安装

ts自动编译

在安装好ts后,在终端输入

1
tsc -init

会产生一个tsconfig.json文件

然后在文件中找到outDir选项,取消注释

1
"outDir": "./js", //代表自动编译后产生的js文件生成在同一目录下的js目录

然后启动监视

可以选择在终端输入

1
tsc -w  //监视多个文件
1
tsc 文件相对位置 -w //监视单个文件

然后保存ts代码,就会自动编译

ts的一些报错

TS2307

Cannot find module ‘./App.vue’ or its corresponding type declarations

在刚创建ts+vue项目时,你在main.ts会发现导入app.vue报错那是因为ts根本不认识.vue

所以在src下的shims-vue.d.ts文件(没有自己创建)下输入

1
2
3
4
5
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}

ts
http://move-brain.github.io/super_zhu/2023/03/03/ts/
作者
super_zhu
发布于
2023年3月3日
更新于
2023年3月14日
许可协议