Why are Typescript applications easier to maintain?
This issue is further compounded as modern projects are significantly larger than their predecessors. It is not uncommon to see websites and mobile projects hit hundreds of thousands of lines of code if not millions and tens of thousands of functions. At this point trying to track down that issue could take days, time which could otherwise be spent in more useful ways such as adding new functionality or improving existing tools/processes.
TypeScript is optionally type-aware so variables and function parameters types can be specified. When a type is specified, it forces the further usages of those variables or function arguments to be of that particular type. So, if a developer inadvertently assigns an incorrect type, the compiler will flag this during the build phase. This enables the developer to identify and fix the issue during compile-time instead of during run-time (where the cost to fix an issue is disproportionately higher).
Why is Typescript not more popular?
It is true that assigning types to variables and arguments takes extra effort. In the long run, however, the effort pays off in terms of simplified maintenance.
Until recently React Native did not officially support a Typescript transpiler. This left a developer with two options:
- Use an unofficial TypeScript transpiler (slow and difficult to setup), or
- Use the beta version of Babel 7 (usable, but with tricky edge-cases)
Neither option presented a compelling case to adopt Typescript for React Native. The outlook for Typescript in 2019 is much better though. Babel 7 has been tagged stable for some time now and portions of React Native are now actively developed using TypeScript. This would be a good time to adopt Typescript for React Native as the primary language/framework for mobile development.
We believe more developers and organizations will recognize the benefits of Typescript and expect to see wide adoption of this technology.
Hopefully this article has persuaded you to use TypeScript in your next project, perhaps convert your current project to use TypeScript or at least piqued your interest to give evaluate Typescript.
If your React Native project is newer than 0.56, TypeScript is recommended as Babel 7 comes bundle by:
If you are using an older version of React Native, you can either upgrade to the latest version if your project permits or better yet follow this to add TypeScript to your project.: