Install the package that resolves ts

1. Why install ts parsing toolkit

Node.js/browser only knows the code of js, they don’t know the code of ts, so you need to convert the ts code to js code first, and then run it, so you need to install a toolkit for parsing ts

2. Install the ts toolkit

After installing globally, you can run the typescript file with the name of the tsc file in the future

cnpm i typescript -g

3. ts-node package

Every time you change the file, you need the tsc file, and then the file generated by node. The steps are too cumbersome. With the help of the ts-node package, you can help us simplify the steps.

Installation: cnpm i ts-node -g

Use: ts-node ts file name

ts-node 1.ts 

ts-node will not generate js files

4. What is a variable?

A variable is a container that can be used to store data and can be changed

5. Generate tsconfig.json file, first npm init -y, then tsc --init

tsc --init

6. The function involves throwing an error and returning the never type

function test (err:string):never {
  throw new Error(err)
}

test('变量不存在')

If it is an endless loop, it is also a never type

Guess you like

Origin blog.csdn.net/Luckyzhoufangbing/article/details/108632890