In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "what are the advantages of TypeScript". In the operation of practical cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Chirag Swadia claims to have been a JavaScript developer for Anti-TypeScript. When it comes to the reasons for the objection, he has always thought that adding types to functions / variables to meet the requirements of the TypeScript compiler is an over-engineering (Over-Engineering) design. Because it doesn't provide any meaningful convenience, and it reduces development efficiency-Chirag says it always encounters some incomprehensible compilation errors in the first place, which takes time to deal with. He also felt frustrated and began to hate TypeScript.
On the other hand, it is difficult for Chirag to understand advanced concepts such as generics in TypeScript. He feels overwhelmed by the fact that he lives in the world of Java, where every line of code is strongly typed. When Chirag started learning TypeScript, he was even afraid of the following simple code.
▲ TypeScript generic example
Therefore, for the above reasons, although Chirag learns TypeScript by watching tutorials or reading books, he has never been involved in any enterprise project written in TypeScript.
The change occurred after Chirag took up the new role, when the technical stack of the project was TypeScript, and all the applications he was responsible for were written by TypeScript (only the remaining code was JavaScript code), so he had to write TypeScript code. As Chirag expected, it was a huge challenge for him at first, and his hatred for TypeScript grew, but finally a few months later, he discovered the benefits of TypeScript and why other people like TypeScript rather than JavaScript.
Chirag also listed three reasons why he became a fan of TypeScript.
The impossible state cannot be recovered and thoroughly checked.
Chirag says this is the main reason why he likes TypeScript. He cites an example of using TypeScript to avoid impossible states in React applications, which describes a case where traffic light systems deal with impossible states (see here).
Errors can be found as soon as possible.
Chirag indicates that when using JavaScript, there have been several situations in which bug was found in a production environment because no type checking was performed at the front end. These bug could have been avoided and could have been discovered by the TypeScript compiler at compile time, saving the cycle of development and QA work.
He believes that with TypeScript, everything can be kept as originally defined, and if a variable is declared as Boolean, it will always be Boolean and will not become a number. This increases the likelihood that the code will work as originally expected. In short, the code is predictable.
Rich IDE support and easy refactoring
Chirag believes that type-related information will make IDE more useful, such as getting functions such as code hopping and automatic completion, and IDE will provide accurate advice. In addition, you get immediate feedback when you enter the code, because the editor marks errors as soon as they occur, including type-related errors. These features can help developers write maintainable code and bring huge productivity gains.
As for refactoring, Chirag gives an example, such as introducing a new state or removing unnecessary state that the application is using, and if you forget to update some references at this time, the TypeScript compiler will warn you. He also said that refactored applications will work the way they were before refactoring, so you don't have to worry about compatibility.
This is the end of the content of "what are the advantages of TypeScript". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.