1. Install node: Go to the official website or use homebrew
2. Check whether the installation is successful
node -v
npm -v
3. Install ts and apply it globally
npm install -g typescript
4. Check whether the installation is successful
tsc -v
5. Configure the idea
and select the installation path of ts. Remember to check Recompile when changing, so that the translated js will be automatically synchronized when operating the ts file.
6. Write a helloworld file and run it to
build the ts file, which will automatically translate and generate an attached js file.
The first way: operate in the terminal:
tsc 文件名.ts
node 文件名.js
The second method:
After writing, click the green hammer on the upper right side of the ts file to build the project. After automatically generating the attachment file with the js suffix, select the js file and click Run
Supplement: Remember that the changed content is the edited ts file, because js is automatically generated based on ts. After you check Recompile when changing in step 5, the changes will be synchronized only after rebuilding after changing the content in ts. js