“This is the fifth day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

This paper introduces MAC terminal commands and the preparation of TS development environment, as well as the creation, compilation and running of TS files by terminal commands

Released by Microsoft in 2012, TypeScript is a superset of JavaScript that can be compiled into pure JavaScript.

TypeScript adds classes, modules, interfaces, and type annotations to provide static checking and type inference.

1. Development environment construction

// Use VScode to write code // node install v14.17.3 node -v // NPM install v8.1.3 NPM -v // typescript install NPM install typescript -g yarn global add typescriptCopy the code

2. MacOS common terminal commands are introduced

Rmdir demo // Delete folder (do not appear in the waste paper basket, not empty or can be deleted, Rm -rf demo // move or rename a directory mvdir demo demoTS // create a file touch demo1.ts // change the file name, temporarily not found, Rm demo1.ts // Copy demo1.ts, And renamed demo2. Ts cp not. Ts demo2. Ts / / search the current directory all ts file find * ts / / display the current directory/Users/XXX/Documents/projects/demo PWD / / // Open the directory in the current command open demo1.ts // Open the specified folder or file // display the contents of the current directory ls -la // View all details ls // View only files // Display or link files Ts // View and edit the file vim demo.ts // Compare the contents of the two directories dircmp dir1 dir2Copy the code

3. Compile the TS file

Ts // Open demo1.ts // Open the file and edit node demo1.ts // Run the file, an error is reported (SyntaxError: TSC demo1.ts // converts ts to js files, resulting in demo1.js // running js files. "Hello World" NPM install -g TS-node // Global TS-node installation plug-in, which can automatically complete the compilation and running of TS files. Do not manually convert ts-node -v // Check the version number v10.4.0 ts-node demo1.ts // Run the ts file directly and output "Hello World" normally.Copy the code