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
To see the effect directly, a right-click menu ha...
Table of contents 1. Union Type 2. Crossover Type...
Netfilter Netfilter is a packet processing module...
1. Overview Redis Cluster enables high availabili...
Table of contents Usage scenarios How to achieve ...
Table of contents background Solution New Questio...
Docker private image library Docker private image...
This article example shares the specific code for...
Preface If you are going to interview for a Linux...
This article introduces an example of using HTML+...
The most understandable explanation of the accura...
Red and pink, and their hexadecimal codes. #99003...
Nowadays, mobile devices are becoming more and mo...
In an article a long time ago, I talked about the...
Copy code The code is as follows: <input type=...