preface

In recent years, Ts is becoming more and more popular in the front end. You also said that VUe3.0 version will support Ts more friendly (from the original flow to Ts, really sweet). Learning Ts and understanding Ts is also an essential trend of the front end. So let’s see, first of all, the basic question three, what is Ts? What does it do? Why do we use it?

What is the TypeScript

The official definition of

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. Any browser. Any host. Any OS. Open source.

TypeScript is a superset of JavaScript types that can be compiled into pure JavaScript. TypeScript compiles JS that can run on any browser, and its compilation tools can run on any server or system. TypeScript is open source.

Simply put, TypeScript is a superset of JavaScript, an open source programming language developed by Microsoft that provides a powerful type system and ES6 support.

What does TypeScript do

  • Type validation helps you find type errors at compile time and can be resolved as soon as possible
  • As a document, what are the attributes, methods, and functions of variables? Look at the type definition
  • IDE enhancements provide code completion, interface hints, jump definitions, refactoring, and more
  • And so on…

Why TypeScript

Why do we choose Ts? What are its advantages?

First of all, there is no doubt that a standardized development will make our code more readable and project more maintainable, but simply enhancing maintainability is not enough to attract us to learn it. Here are some other points:

  • The original.jsFile, without any changes, can be directly changed to.ts
  • If there is no type annotation, it can be inferred automatically
  • Error compiling? Js files will not be generated
  • Separate type files can be written for TypeScript to read to accommodate third-party libraries that are not written in TS
  • Support for the ES6 specification, even some draft specifications
  • Active community ecology is not only a powerful backer, but also a great thrust for the development of a language

The disadvantage of TypeScript

No one thing can be perfect. Besides its advantages, Ts also has some disadvantages:

  • Learning costs, learning Ts, requires an understanding of concepts unfamiliar to front-end development, such as Interfaces, Generics, and so on
  • Development cost, need to add more type definition during development, need to develop cost in a short time
  • Using -> Integrate -> Build, the whole process is a bit more work
  • Not all libraries work together perfectly

conclusion

Ts currently in use of the project on the front end is not mandatory, just as a trend of future front-end development, the main team and project, or go to a company may introduce cost really is too high for your old project, the team will not do, and for the development of new projects, or can consider introducing Ts, after all, all things are difficult before they are easy, difficult is only temporary.