Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
Download the node. Js
- Download it at nodejs.org/en/
Installation node. Js
- No special operations are required. Select an installation path and install it directly
- After installation is complete, use
win+R
Shortcut keys Open the CMD command line window, and enternode -v
Check whether the installation is successful
If the preceding version number is displayed, the installation is successful
Install the toolkit for parsing TS
- The CMD command-line interface is displayed
- Good speed
- Input:
npm install -g typescript
- NPM: Package manager
- Typescript: a tool kit for parsing TS. TSC implements TS -> JS
- Input:
- Internet connection is bad
- First the input:
npm config set registry https://registry.npm.taobao.org
(Taobao Mirror) - Check:
npm config get registry
- Input:
npm install -g typescript
- First the input:
- Good speed
- Check whether the installation is successful
- Enter TSC and the installation succeeds if a bunch of code appears
Method 1: Use notepad to write
- Create a Notepad file
- Enter the following code
console.log('Hello TS') Copy the code
- Save and modify the.ts extension
- Go to the cli and enter
TSC File name. Ts
- Ts files can be converted to JS files
Method 2: Use VScode to write
-
Open VScode and create a new folder
-
Open the terminal and type TSC –init to bring in the TS compilation rule configuration file tsconfig.json
-
Modify “outDir”: “./” to “outDir”: “./dist” and uncomment in the tsconfig.json file
"outDir": ". /" /*outDir specifies the output folder. The value is a string of folder paths where output files will be placed */ Copy the code
-
Create a new file named Hello.ts
-
Enter the following code
console.log('Hello TS') Copy the code
-
Click the menu bar -> Terminal -> Run Tasks -> Select current Folder -> TSC Monitor
- Enable monitor to update JS files in real time
Method 3: Use WebStorm to write
- Open webStorm, create a new directory, and create a new TS file
- Enter the following code
console.log('Hello TS') Copy the code
- Click Terminal in the lower left corner to enter
TSC File name. Ts
- Ts files can be converted to JS files