Using Typescript With React Native
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.