1. Introduction to TypeScriptThe previous article introduced the installation, use, and automatic compilation of TypeScript. Click to view if you need it. Introduction to TypeScriptTypeScript is an open source, cross-platform programming language developed by Microsoft. It is a superset of JavaScript and will eventually be compiled into JavaScript code. In October 2012, Microsoft released the first public version of TypeScript. On June 19, 2013, after a preview version, Microsoft officially released the official version of TypeScript. The author of TypeScript is Anders Hejlsberg, the chief architect of C#. It is an open source and cross-platform programming language. TypeScript extends the syntax of JavaScript, so any existing JavaScript program can run in a TypeScript environment. TypeScript is designed for large-scale application development and can be compiled to JavaScript. TypeScript is a superset of JavaScript that mainly provides a type system and support for ES6+. It is developed by Microsoft and the code is open source on GitHub. TypeScript is a superset of JavaScript that provides a type system and support for ES6+. It was developed by Microsoft and its code is open source on GitHub (opens new window) Features of TypeScriptTypeScript has three main features: From JavaScript to JavaScript Strong type system Advanced JavaScript SummarizeTypeScript is becoming more and more popular in the community. It is very suitable for some large projects and some basic libraries, which greatly helps us improve development efficiency and experience. 2. Install TypeScriptRun the following command on the command line to install TypeScript globally: npm install -g typescript After the installation is complete, run the following command in the console to check whether the installation is successful (3.x): tsc -V 3. Your first TypeScript programWriting TS programssrc/helloworld.ts //The parameter str is of type string. function aa(str: string){ return "Hello" + str } let text = 'little cutie' console.log(aa(text)) src/index.html //If the ts file is directly imported, the browser will report an error (if the ts file only contains the js syntax of the word, it can be imported and used normally) <script src="./helloworld.ts"></script> Manually compile the codeWe used a .ts extension, but this code is just JavaScript. In your terminal, run the TypeScript compiler: tsc helloworld.ts The output is a helloworld.js file that contains the same JavaScript code as the input file. In the terminal, run this code through Node.js: node helloworld.js Modify src/index.html <script src="./helloworld.js"></script> Console output:
Let's look at the code in helloworld.js function aa(str) { return "Hello" + str; } var text = 'Little cutie'; console.log(aa(text)); Summarize
vscode automatic compilation1). Generate the configuration file tsconfig.json step: tsc --init 2). Open the file and modify the tsconfig.json configuration "outDir": "./js", "strict": false, 3). Start monitoring task:
Modify and save again, and the corresponding js file will be automatically generated. The above is the detailed content of the tutorial on how to install, use, and automatically compile TypeScript. For more information about the installation and use of automatic compilation of TypeScript, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: Basic security settings steps for centos7 server
>>: An example of how to query data in MySQL and update it to another table based on conditions
After a long period of transplantation and inform...
Table of contents JavaScript events: Commonly use...
1. Introduction to Data Integrity 1. Introduction...
As a Vue user, it's time to expand React. Fro...
1. Command Introduction The ifconfig (configure a...
Table of contents Chain calls A small case Chain ...
Under Ubuntu 18.04 1. sudo apt install python ins...
Linux installation MySQL notes 1. Before installi...
Note: It is recommended that the virtual machine ...
The find command is mainly used to find directori...
This article example shares the specific code of ...
Table of contents 1. Problem Discovery 2. View de...
Modern browsers no longer allow JavaScript to be ...
In Docker's design, a container runs only one...
Alibaba Cloud Server cannot connect to FTP FileZi...