当前位置:网站首页>[ts]typescript learning record pit collection
[ts]typescript learning record pit collection
2022-07-29 09:49:00 【Two water first wood show】
Catalog
Two 、tsc --watch Monitor synchronous changes
2.1 An empty class cannot generate the corresponding js file edit
2.2 Delete ts Files will not be deleted synchronously js file
2.3 modify ts File name problem
2.4 modify ts File folder name problem
3、 ... and 、import Auto import classpath exception problem
3.1 The same name ts Class problem
Four 、 Residual parameter problem ( ...params:any )
5、 ... and 、JSON jsonObj turn string problem
Environmental Science
IDE: Visual Studio Code 1.69.1
npm 8.1.2
node 16.13.2
tsc 4.7.4
Supplementary instructions for beginners :
tsc -init Generate tsconfig.json
tsc /fileA/xxx.ts Generate xxx.js File to outDir Under specified directory fileA/xxx.js
node /outDir Catalog /fileA/xxx.js perform xxx.js file
One 、tsconfig.json
"strict": true Enable all strict type checking options .

If strict checking does not need to be enabled, it is false.
"outDir": "./js"// You want to generate js The catalog of
ctrl + ` Start the terminal : perform tsc --watch Turn on monitoring ts Change synchronization js change
ctrl + shift + ` Open a new terminal
Two 、tsc --watch Monitor synchronous changes
2.1 An empty class cannot generate the corresponding js file

2.2 Delete ts Files will not be deleted synchronously js file
2.3 modify ts File name problem
modify ts After the file name vscode All... Will be opened synchronously import With this ts Class , Let you save it manually , To synchronize to all corresponding js Of documents import changes .
It is called before modification FoodApple.ts
Modify the back foot foodapple.js Will open main.ts file ( It quoted FoodApple.ts) Let you save it manually , All files need to be saved manually before they can be synchronized js, If you close it directly at this time vscode, It doesn't sync ,js The code will be with you ts There are differences in the code , Unless you modify the corresponding ts Save before synchronization takes effect .

Be careful import The corresponding file name foodapple.ts( Not the class name inside FoodApple No impact )

At the same time, modifying the file name will add a js( That is, the new file name .js) At the same time js Files will not be deleted synchronously You need to delete it manually .
2.4 modify ts File folder name problem
After modifying a folder name , All that involve the folder name import All documents will be vscode open , Let you save it manually , Save one by one before synchronizing js, also js The folder name under the directory will not be modified synchronously , You need to manually modify JS Folder name . The following is before and after modification




3、 ... and 、import Auto import classpath exception problem
3.1 The same name ts Class problem
If it is found that the automatic import does not work normally , Or if you have imported this class, but there are always exceptions and errors when using this class , That must be the same name ts class .( Compilation is passed )
Four 、 Residual parameter problem ( ...params:any )

Guess what the output is ?
.
.
.
.
Yes !funcA What we get is a any[], altogether 4 The difference is 1, "a", true, 3.14.
funcBBB What we get is a any[], however , caller funcA Only one parameter, namely ([1, "a", true, 3.14])any Array . So the output is 1,a,true,3.14. Because it's just an array ( Tuples ?)


If you want to funcBBB Getting is also and funcA The same thing , Just put funcBBB(...params:any) Change to funcBBB(params:any) that will do .


summary : ... Is the keyword of the remaining parameters , Parameters marked by this remaining parameter keyword , It's not something special similar C# That kind of , It can only be directly understood as ...params:any Equate to any Array , But it is better than direct definition any[] The advantage is that the caller can pass any number any Go in and package it into an array , And the default is nullable That is, you can pass no parameters . then , When you want to continue delivering this ... Tagged parameters params when , Bear in mind ! Bear in mind ! Don't use the parameter of the method passed in ... The remaining parameter keywords are defined , Otherwise, it's equivalent to you putting params Array passed to a new array , Then you can only use parameters in the method body you pass in [0] Get the array passed in .
Some places don't understand ... How to use , Someone may define it as : ...params:any[], But it was not passed on to it any[], Just a single variable , In fact, there is a problem , According to my understanding, there is a problem , It is reasonable to report an error , If the user puts params[0] Used as an array , But what we actually get is a single variable such as int. It must be wrong .
ts + js + vscode + git It's almost out of the sky ~
5、 ... and 、JSON jsonObj turn string problem
Map<key,value> Unable to successfully transfer string It must be rewritten as { [key]=value } Form can be successfully transformed string
for example :
let json : any = {};
for(let key of map.keys()){
json[key] = map.get(key);
}
JSON.stringify(json, null, 1); Output complete dictionary json character string ( Back 2 Parameters are used to show the indented json)
边栏推荐
- Anfulai embedded weekly report no. 273: 2022.07.04--2022.07.10
- Intel joins hands with datawhale to launch learning projects!
- What is Cartland number? What are the applications?
- Senparc.Weixin.Sample.MP源码剖析
- 核酸扫码登记体验有感(如何提高OCR的文字正确识别率)
- Unity3d空包打apk报错汇总
- How to export the old and new file names and locations to excel after file renaming
- Configuration file settings for remote connection to Windows version server redis
- Unity3d hodgepodge
- Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice
猜你喜欢

MySQL事务与MVCC如何实现的隔离级别

Webassembly 2022 questionnaire results are fresh

vector实现

First order traversal / second order traversal determines the approximate shape of the tree

WebAssembly 2022 问卷调查结果新鲜出炉

核酸扫码登记体验有感(如何提高OCR的文字正确识别率)

Intel joins hands with datawhale to launch learning projects!

i. Mx6ull driver development | 32 - manually write a virtual network card device

Four types of technical solutions shared by distributed sessions, and their advantages and disadvantages

7.9-7.17 new features and grammar of learning plan ES6
随机推荐
2021年CS保研经历(四):西交软院预推免、信工所三室预推免
那句话的作用
Fluent text editor
On contract testing
Nutnews developed based on arkui ETS
Solve the problem of reading data garbled by redis visualization tool
Problems and solutions of introducing redis cache
Summary of introduction to unityshader (2): Beginner Level
How to introduce your project experience?
Intel joins hands with datawhale to launch learning projects!
[苹果开发者账号]06 转让开发者账号后,开发者年费自动续费问题
2021年CS保研经历(六):系统填报 + 一些感想
RTMP supports h265 streaming
当 update 修改数据与原数据相同时会被更新吗?
Explanation of trie tree (dictionary tree)
一文读懂Plato Farm的ePLATO,以及其高溢价缘由
Div horizontal arrangement
Div horizontal layout aligned on both sides
Source code analysis of senparc.weixin.sample.mp
读博后降维打击数学建模!