I used to work on Microsoft’s back-end projects, but as the company’s business grew, I shifted to the development of front-end projects. Today, I’m here to talk about TypeScript, which Microsoft leads. If you have used C# or Visual Basic.net, you will be familiar with it.

Typescript origin

Prior to the release of Microsoft’s powerful visual studio2012, Javascript support was shit, and it wasn’t until VS2012 that it made a significant leap forward. It is estimated that Microsoft’s internal efforts to upgrade VS also found that Javascript was flawed because it was not suitable for building large-scale applications. I guess Sync started Typescript development around that time, maybe even earlier. Microsoft officially released Typescript 2012 on September 12, 2012, followed by the release of Typescript on October 1, 2012, when it became open source.

It’s fair to say that Typescript’s arrival is inseparable from Microsoft’s open source strategy. It’s fair to say that Anders Hejlsberg is a believer in open source. NET core engine CoreCLR open source, he later led the Typescript open source.

It’s fair to say that Typescript’s arrival is inseparable from Microsoft’s open source strategy. It’s fair to say that Anders Hejlsberg is a believer in open source. NET core engine CoreCLR open source, he later led the Typescript open source.

Introduce Typescript

TypeScript is a superset of JavaScript, so any JavaScript is legitimate TypeScript (much like the RELATIONSHIP between C and Objective-C). TypeScript combines type checking with static analysis and explicit interfaces. TypeScript is Microsoft’s open source project started by Anders Hejlsberg, the father of C#.

What does Typescript do?

JavaScript is just a scripting language, not really designed to develop large Web applications. JavaScript doesn’t provide concepts like classes and modules. For real application development, TypeScript extends JavaScript and implements these features.

TypeScript features include:

  • Microsoft’s open source language, under the Apache license
  • Added static types, classes, modules, interfaces, and type annotations
  • Can compile to readable, standardJavaScript
  • Support large-scale developmentJavaScriptApplications that support all browsers, hosts and operating systems
  • Can be used to develop large applications, and ensure that compiledJavaScriptCode compatibility
  • Easy to learn and understand

Typescript and JavaScript are similarities and differences

TypeScript extends the JavaScript object model from both the core language aspect and the modular aspect of class concepts, so existing JavaScript code can be used with TypeScript without any modifications. TypeScript provides compile-time static type checking through type annotations. TypeScript processes existing JavaScript code and only compiles TypeScript code within it.

Let’s look at the table:

Compare the project TypeScript JavaScript Pay attention to
Basic types of boolean number string Array Tuple Enum any void null undefined never object string number boolean null undefined symbol Object in TypeScript represents a type that is not a JavaScript primitive type
Variable declarations let const var let const var Almost the same
interface interface There is no Type checking is at the heart of TypeScript, so interfaces play the role of naming those types
class Class abstract class readonly… The class without the abstract class Similar, but different in the future. TypeScript uses private to define private, while JavaScript will most likely use #.xx to define private writing standards. TypeScript supports abstract classes, read-only classes, and so on.
function N N Basically the same, parameters assigned to default values, remaining parameters, etc. The only difference is TypeScript support, right? Optional parameters
The generic Generics There is no Generics are a particularly flexible and reusable type that specifies different types to control the types that TypeScript supports
The enumeration Enums There is no TypeScript supports enumerations that not only start at 0 by default, but also assign specific strings, which have a lot of room to manipulate
Type inference support There is no let x = 3; TypeScript can infer from 3 that x is of type number
Higher order type & typeof instanceof… There is no TypeScript unique
Symbols N N As the Symbol
The iterator N N If symbol. iterator is implemented, it is considered iterable, as defined in JavaScript terminology
Generators N N The same
Module system N export import TypeScript supports a wide variety of module systems, including ESModule, Commonjs specification, and even AMD UMD
other N N Because TypeScript is a superset of JavaScript, apis defined by ES2016 and ESNext can be used directly in TypeScript without language support. Others, such as JSX Mixins, These are not part of the JavaScript standard so I won’t repeat them here.

Let’s take a look at TypeScript’s powerful type checking

Similarities and differences between C# and Typescript

While C# and Typescript are both Microsoft’s leading efforts, led by Anders Hejlsberg, they have a lot in common, so let me look at Typescript from the perspective of a C# programmer.

C# value types are further subdivided into simple types, enumerated types, structural types, and null-capable value types. C# reference types are subdivided into class types, interface types, array types, and delegate types.

Compare the project TypeScript C# instructions
The numerical number Int, long, float, double, byte, char, decimal, etc In TypeScript, like JavaScript, all numbers are floating point and are represented by number, which saves C# from long to int overflow problems.
Boolean type Boolean Boolean Is essentially the same
The enumeration enum enum Javascript does not have enums, which TypeScript complements. Functionally similar to C#; The goal is to provide friendly names for values that increase code readability and refactorability; C#’s enumeration value toString() returns the text value of the enumeration, whereas TypeScript is a numeric value
string String String Basically the same, except that TS supports single quotes
Symbol Symbol There is no Used as a unique Symbol, all new symbols are different, regardless of whether the values passed in are the same. It’s perfect for keys
any any dynamic Dynamic is a new feature in FrameWork4.0. By default,dynamic objects support any feature you want at compile time
void void void Same, means nothing
null null null Basically the same, note that the value type in C# cannot be set to null and must be given a concrete value
undefined undefined There is no
never never There is no Is introduced by TypeScript as a semantic type to indicate that a value will never be returned, such as while(true){} or throw new Error().
Array Array Array Arrays in C# can be combinedLinqQuite powerful, but TS can also be used with third-party libraries such aslodashTo implement the
tuples deconstruction Tuple Similarly, the old version of C#TupleA bit weak, but C#7.0 has been updated and TS deconstruction is also available

conclusion

This article introduces me to the history of TypeScript and the similarities and differences between TypeScript and JavaScript as well as C# and TypeScript. If you have learned Java, VB, C# and PHP and have a basic knowledge of JavaScript, Thank you for your interest. Let’s give it a try.

The resources

Official TypeScript Handbook