Use Typescript in React Native in Just 2 Lines

Anthony
1 min readMar 30, 2019

--

After reaping the benefits of TypeScript’s strong typing and delving into the world of React Native in search of a reusable, component-based, and multi-platform architecture with few compromises, you’ve probably wondered how to convert your React Native project to Typescript.

Same.

I’ve found that there are dozens of articles on this topic, so I figured I’d save you some reading time and get you up and running––so here’s my solution.

Introducing react-native-tsx! All you have to do to convert your entire React Native project to be Typescript-based is the following…

TL;DR

Run npm install -g react-native-tsx to install the module and then simply react-native-tsx from the root directory of your project. That’s it!

What will this do? You’ll install Typescript , tslint , and a few other essential node modules while removing some unnecessary babel dependencies. Then, all your js files will turn intotsx files, and voila, you’ve got yourself a fresh React Native project compiled from Typescript, allowing JSX grammar.

Be sure to configure your app.json correctly when using Expo, too!

That being said, enjoy the few minutes of your life that I’ve spared. 🎉

--

--

Anthony
Anthony

No responses yet