What is TypeScript?
TypeScript is JavaScript with a type system added for projects of any size. By describing TypeScript’s two most important features: the type system and its applicability to any size.
The characteristics of the TypeScript
Speaking of TypeScript, we need to talk about its prototype JavaScript, which we all know is a very flexible single-threaded language:
- There is no type constraint, and a variable may be initialized as a string and later assigned as a number.
- Because of implicit type conversions, some variable types are difficult to determine before running.
- Prototype-based aspect object programming allows properties and methods on a prototype to be modified at run time.
- Functions are first-class citizens of JavaScript and can be assigned to variables, as arguments, or as return values.
Problems with this flexibility also arise, such as variable code quality, high maintenance costs, and runtime errors. Typescript’s type system largely compensates for JavaScript’s shortcomings.
TypeScript is static
The type system is divided into dynamic types and static types according to the timing of type checking.
Dynamic typing: type checking is performed only at run time. In this language, typing errors often lead to runtime errors. JavaScript is an interpreted language with no compile phase and dynamic typing.
Static typing: When the type of each variable is determined at compile time, this language often leads to syntax errors. TypeScript is static and needs to be compiled to JavaScript before it can be run. TypeScript is typed at compile time.
Most JavaScript code becomes TypeScript code with very little (or no) modification because of TypeScript’s powerful type inference [], even without manually declaring the type of variable foo, It can also automatically infer that a variable is of type number when it is initialized.
TypeScirpt is a weak type
The type system is classified by whether implicit conversions are allowed, and can be divided into strong and weak types. TypeScript is fully compatible with JavaScript. The core design concept of TypeScript is to keep JavaScript runtime behavior intact while introducing static systems to make your code maintainable and less buggy.
Suitable for any size
TypeScript is ideal for large projects because the type system allows for higher maintainability, and most types don’t need to be declared manually due to [type corollary][], and, TypeScript enhances the compiler’s (IDE) capabilities, including code completion, interface hints, jump definitions, code refactoring, and more, which greatly improves development efficiency. If you think type checking is too strict, you can also lower the standard by modifying the compile options.
Install the TypeScript
TypeScript command-line tools are installed globally as follows:
npm install -g typescript
Copy the code
The compiler
While major compilers support TypeScript, Visual Studio Code is recommended. Download and install: code.visualstudio.com/
This article is excerpted from the following article:
TypeScipt Introduction