当前位置:网站首页>安装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文件,帮到你的小伙伴记得一键三连哦!谢谢小伙伴的支持!!
有缘人才可以看得到的哦!!!
边栏推荐
- Eureka service registration and discovery
- [interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV
- Use full function simulation design method
- 2021-08-21
- Valid parentheses
- Reasons for the failure of digital transformation and the way to success
- SQL performance optimization method for interval retrieval
- Dynamic tree + data table + pagination of spa project development
- Crud+ form verification for spa project development
- 【知乎知识主推荐】 无人机中的城堡- 专注于无人机在不同技术领域的应用
猜你喜欢

There are 15 necessary knowledge points for the second level cost engineer before the exam! I wish you success!

【ROS 入门学习 】CmakeList.txt 和Packages.xml释义
![组合总数[标准回溯 + 回溯技巧--降低栈深度]](/img/88/3a07589bf8edab618139b1bf1680e8.png)
组合总数[标准回溯 + 回溯技巧--降低栈深度]

Some shaders in AB package do not trigger the callback of ipreprocessshaders

In the middle of the year, we will promote the integration of worry free, and the value-added package will be reduced by 6

What are the methods of software stress testing and how to select a software stress testing organization?

2021-04-16

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

【几何法视觉】4.2 分段线性变换

The relationship between derivative and differential of function
随机推荐
【知乎知识主推荐】 无人机中的城堡- 专注于无人机在不同技术领域的应用
Cryptography series: certificate format representation of PKI X.509
A group of K overturned linked lists [disassembly / overturning / assembly of linked lists]
Total number of combinations [standard backtracking + backtracking techniques -- reducing stack depth]
Mask image modeling for self supervised representation pre training: CAE and its relationship with Mae and Beit
Las point cloud create mesh
2021-08-21
[GWCTF 2019]mypassword XSS
redis 报错解决与常用配置
Some shaders in AB package do not trigger the callback of ipreprocessshaders
2021-05-02
[chess life] 01 life is like chess
What if the SQL execution plan of the production system suddenly becomes worse?
【ROS】ROSmsg cakin_ Make compilation error
Greedy interval problem (4)
Delphi SOAP WebService 服务器端多个 SoapDataModule 要注意的问题
Developing salary management system based on C language course paper + source code and executable EXE file
Analysis of open API design specification
Which is the higher priority of V-IF or V-for?
Vs code one key sorting shortcut