当前位置:网站首页>安装typescript环境并开启VSCode自动监视编译ts文件为js文件
安装typescript环境并开启VSCode自动监视编译ts文件为js文件
2022-06-22 20:45:00 【掉发的小王】
一、前言
小编最近开始学习typescript,懂得人都知道,typescript是vue3的基础伴生,配合更加默契。就像vue2和js一样!typescript不像js那样浏览器直接可以解读,需要我们把ts文件编译成js文件,这样浏览器才可以解读。所以我们要安装一下ts的环境和自动编译,方便我们后续学习,不需要写完一个ts文件在手动编译!
二、安装typescript环境
必须要有node环境哈!
win + R 输入cmd
npm install -g typescript
-g代表global全局安装
查看版本
tsc -v

三、VSCode配置自动监视编译
1. 新建一个文件夹

2. 在终端打开

3. 初始化配置文件
tsc --init

4. 编辑配置文件
52行修改生成的js文件存放位置为:json文件夹所在目录的js文件夹下,js不存在会帮助我们新建!
79行我们关闭语法检查,随意一点哈!(根据个人喜好设置)

5. 开启自动编译
找到终端,点击运行任务
点击显示所有任务
找到要监视的json文件

出现报错:
error TS18003: No inputs were found in config file
'd:/file-wang/vue/code/test/tsconfig.json'.
Specified 'include' paths were '["**/*"]' and 'exclude' paths were '["./js"]'.

我们不要着急,这是没有监视到ts文件,所以提示的,我们不用管,直接写一个ts测试一下!
四、测试
1. 编写ts文件
新建test.ts
(() => {
function helloWord(str:string){
return '这是第一个ts程序:' + str
}
var text = 'helloword'
console.log(helloWord(text))
})();
我们发现,js文件夹下已经给我们编译成js文件了!

2. 编写html文件
我们直接引入js文件夹下的js文件!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./js/test.js"></script>
</body>
</html>
3. 浏览器测试
我们在test.html页面按住快捷键:alt + B在浏览器打开次html文件
我们F12看看是否输出了:这是第一个ts程序:helloword
五、总结
这样就完成了基础的安装和配置自动监视ts文件编译成js文件,帮到你的小伙伴记得一键三连哦!谢谢小伙伴的支持!!
有缘人才可以看得到的哦!!!
边栏推荐
- Talk about SQL profile again: can I fix the execution plan?
- 322. change exchange
- In a frame because it set 'X-FRAME-OPTIONS' to' deny '
- Three cache methods and principles
- Uniapp applet mall develops thinkphp6 points mall, group purchase and seckill packaged app
- Task management of embedded development foundation (thread management)
- Generate detailed API and parameters of QR code using qrcodejs2
- Technology cloud report: East to West computing is not only about "computing", but also needs "new storage"
- [path planning] week 1: hodgepodge
- 【ROS 入门学习 】CmakeList.txt 和Packages.xml释义
猜你喜欢

NFT can only be viewed from afar, but not blatantly played

2021-04-16

pycharm 配置远程连接服务器开发环境

【论文解读】关于基于视觉无人机自主降落平台的论文梳理

2020-12-04

2021-08-22
![[recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields](/img/3b/8916c543c149292221ce500209df0d.png)
[recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields

Uniapp applet mall develops thinkphp6 points mall, group purchase and seckill packaged app

Note: by the end of 2022, the printing entrance of Guangdong second-class cost engineer's admission card has been opened

新捷途X70S上市8.79万起,空间安全越级,不愧是网红国民大7座SUV
随机推荐
General trend wisdom to create inclined model and cut monomer
[interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV
Lua -- iterator, module, meta table
5分钟快速上线Web应用和API(Vercel)
Mysql database DQL query operation
Crud+ form verification for spa project development
Lua-- use of data types, variables, loops, functions and operators
LinkedList 源码解析
【几何法视觉】4.2 分段线性变换
R language builds a binary classification model based on H2O package: using H2O GLM constructs regularized logistic regression model and uses H2O AUC value of AUC calculation model
《强化学习周刊》第50期:SafeRL-Kit、GMI-DRL、RP-SDRL & 离线元强化学习
Greedy distribution problem (1)
Eureka service registration and discovery
Rendu stéréo
Huawei cloud recruits partners in the field of industrial intelligence to provide strong support + commercial realization
. Net 5.0 realizes the source code analysis of the oidc authentication part of single sign on through identityserver4
Las point cloud data thinning in ArcGIS
Redis error reporting and common configurations
【论文解读】关于基于视觉无人机自主降落平台的论文梳理
How to continuously improve performance| DX R & D mode