What is Pros and Cons of Typescript
Advantages / Pros:
1. Optional static typing
TypeScript introduces optional strong static typing: Once declared, a variable doesn’t change its type and can take only certain values. The compiler alerts developers to type-related mistakes, so they have no opportunity to hit the production phase. This results in less error-prone code and better performance during execution
It’s important to note that TS doesn’t force declaring types everywhere. Developers are free to change the level of type strictness in different parts of the project. This approach distinguishes TS from other statically typed languages and allows you to find the right balance between flexibility and correctness
2. Early spotted bugs
Researchers found that TypeScript detects 15 percent of common bugs at the compile stage. So instead of spotting bugs at runtime, you can detect them earlier at compiled time. It saves a lot of efforts
3. Predictability
With TypeScript, everything stays the way it was initially defined. If a variable is declared as a string, it will always be a string and won’t turn into a Boolean. This enhances the likelihood of functions working the way initially intended
4. Readability
Due to adding strict types and other elements that make the code more self-expressive (so-called syntactic sugar), you can see the design intent of developers who originally wrote the code. It’s especially important for distributed teams working on the same project. A code that speaks for itself can offset the lack of direct communication
5. Power of OOP
TypeScript supports concepts from class-based object-oriented programming (OOP) like classes, interfaces, inheritance, and more. The OOP paradigm facilitates building a well-organized scalable code, and this advantage becomes more obvious as your project grows in size and complexity
6. Cross-platform and cross-browser compatibility
You can use TypeScript to build cross-platform apps in less development time than building separate versions for each platform and device. And it’ll help you reach a broader user audience much quicker
7. Others
Some other advantages like: IDE supports, faster refactoring,...
Disadvantages / Cons:
1. Not true static typing
Apart from the fact that this feature is optional for TS, eventually it is transpiled into untyped JavaScript, so there is always the risk of weird type conversions at runtime
2. Bloated code
Basically, compare to plain JS, developers will need to write more codes and spend more time on resolve some conflicts, but it will pay off in the end