当前位置:网站首页>安装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文件,帮到你的小伙伴记得一键三连哦!谢谢小伙伴的支持!!
有缘人才可以看得到的哦!!!
边栏推荐
- Delphi SOAP WebService 服务器端多个 SoapDataModule 要注意的问题
- 2021-01-29
- Greedy distribution problem (1)
- [mavros] mavros startup Guide
- 2021-08-21
- [recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields
- The first warm-up -- implicit type conversion or other?
- [ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design
- Remote access and control - SSH Remote Management and TCP wrappers access control
- Reasons for the failure of digital transformation and the way to success
猜你喜欢

Explain the startup process of opengauss multithreading architecture in detail

《强化学习周刊》第50期:SafeRL-Kit、GMI-DRL、RP-SDRL & 离线元强化学习
Solution to cache inconsistency

Why is yuancosmos so popular? Is the 10trillion yuan shouted by the market boasting or the truth?

The required reading for candidates | PMP the test on June 25 is approaching. What should we pay attention to?

Some shaders in AB package do not trigger the callback of ipreprocessshaders
![A group of K overturned linked lists [disassembly / overturning / assembly of linked lists]](/img/70/fb783172fa65763f031e6bd945cbd9.png)
A group of K overturned linked lists [disassembly / overturning / assembly of linked lists]

Redis error reporting and common configurations

2021-08-22

The method of making videos of knowledge payment system support m3u8 format playback
随机推荐
[mavros] mavros startup Guide
LinkedList source code analysis
Greedy interval problem (4)
Enabling partners, major guarantee of Spring Festival "non-stop"
There are 15 necessary knowledge points for the second level cost engineer before the exam! I wish you success!
[geometric vision] 4.2 piecewise linear transformation
pycharm 配置远程连接服务器开发环境
2021-01-29
shell(34) : 時間
Next permutation [give play to subjective initiative to discover laws]
【ROS】ROSmsg cakin_ Make compilation error
Note: by the end of 2022, the printing entrance of Guangdong second-class cost engineer's admission card has been opened
Summary of just meal with 900W increase in playback and acclaim from station B users
2021-08-21
Grafana report display of sentinel based high availability current limiting system
Developing salary management system based on C language course paper + source code and executable EXE file
Dynamic tree + data table + pagination of spa project development
Mysql database DML operation exercise
One case of SQL performance degradation caused by modifying implicit parameters
Codeup longest palindrome substring