TypeScript static checking

Reference Why use TypeScript? What scenarios please briefly explain, or by example?

TS JS improvements are mainly static type checking, static type checking what is the significance? The standard answer is "static typing is more conducive to building large applications." Why static type is conducive to building large applications? Interest in two points.

First, the static type checking can be done early fail, even if you write the code that is not executed to occur as soon as you write code type does not match the language (interpreted too, before you can run) at compile time to Find. For large applications, branch coverage test debugging difficult, not necessarily a lot of code to be able to perform in all conditions. And if your code as simple as any changes can be reflected from the UI out, it does not take a large application with the relationship, then the static type checking is really no effect.

Second, it is the best type of comments. Static type of reading the code is friendly, such as our example jQuery API Documentation which is we are very fond of using jQuery.ajax, in this document, the detailed explanation of the type of object the only parameter settings, it is is so complicated, if there are no documents, we look at the function declaration, it was impossible to guess the usage right. For large applications, a number of methods, call the complex relationship, not every function there are people who write detailed documentation, so the static type is very important tips and constraints. And if you like jQuery code so that all basic functions are all API, did not have an internal function, but logic seems obvious, it does not take a large application with the relationship, then the static type of reading the code does nothing to help. In general, modern programming language design, many features have been very mature theoretical support, if we pay attention to computer-based, so some of the language of the applicable scene is like a fight building blocks, can be summarized in a few words. TS like to JS so, just change a single feature.

Here Insert Picture Description

Published 21 original articles · won praise 51 · views 5550

Guess you like

Origin blog.csdn.net/liuyifeng0000/article/details/104092420