<> Why? TypeScript Will become a trend ?

<> One , What is? TypeScript?

* TypeScript yes JavaScript Superset of type of , It can be compiled into pure JavaScript.
* Compiled JavaScript Can run on any browser .
* TypeScript Compilation tools can run on any server and any system .
* TypeScript It's open source .
<> Two , Why use TypeScript?

* TypeScript Increased code readability and maintainability
* Type systems are actually the best documentation , Most functions can see the definition of type to know how to use it
* Most errors can be found during the compilation phase , It's better than making a mistake at runtime
* TypeScript Very inclusive
* TypeScript yes JavaScript Superset of ,.js Files can be renamed directly to .ts that will do
* Can define almost all types from simple to complex
* Compatible with third-party libraries , Even if the third-party library is not used TypeScript Written , Separate type documents can also be prepared for TypeScript read
* TypeScript Have an active community
* Most third-party libraries are available to TypeScript Type definition file for
* Angular and VSC They all use TypeScript Prepared by
contrast JS And TS The difference between , To understand TS The beauty of .
/* Read this JS method , We know it takes a parameter a. So about this parameter a Any information about , We don't know .
We can only read this way , To infer this parameter a Type format for . */ function sortName(a) { var result = a.slice(0);
result.sort(function (x, y) { return x.name.localeCompare(y.name); }); return
result; } /* Read below ts code , We see us as parameters a Type defined . parameter a Type mapping to a Person Interface of , There must be name and age parameter .
And name Parameter type is string,age Parameter type is number. Through such a clear type definition , We don't look at methods , We can understand the function of the method, and we can transfer the parameter .
This allows you to , It's easier to find out the error of our code . */ interface Person { name: string; age: number; }
function sortName(a: Person[]) { var result = a.slice(0); result.sort(function (
x, y) { return x.name.localeCompare(y.name); }); return result; }
<> Three , How to install and compile

​ install
npm install -g typescript
Manual compilation ts file
tsc helloworld.ts
Automatic compilation ts file

generate tsconfig file :
tsc -init
Click terminal => Run task => tsc: monitor - tsconfig.json

©2019-2020 Toolsou All rights reserved,
vue In the project axios Global encapsulation of 2021 year 2 Monthly programmer salary statistics , average 15144 element Classical algorithm - recursion ( The case of raw rabbit ) One article reveals Ali , tencent , Salary rank of Baidu Thorough explanation from Zhongtai Unity Scene loading asynchronously ( Implementation of loading interface )SpringBoot practice ( five ):mybatis-plus In BaseMapper,Iservice and ServiceImplVue Common features ( one ) What should I do if I suddenly encounter a question I can't answer during the interview ?Bug Can data be used as the basis of technical personnel assessment KPI?