Image for post
Image for post
Photo by Marten Newhall on Unsplash

Should You Use TypeScript with React Native? [2021]

Spencer Carli
Jan 27 · 4 min read

If you’ve spent much time looking around the React/React Native bubble you’ve likely heard of TypeScript (if not no worries — we’ll discuss it more here).

I know that I have and, honestly, I’ve all but ignored it up to this point.

But I’m examining the tools I use in my React Native apps to see what I can change/improve.

One of those is TypeScript. Tons of people love it.

So let’s take a look.

This is just my initial analysis as I investigate whether I want to invest in TypeScript or not. If I’m wrong on something I would love to learn more. Let me know on Twitter.

What is TypeScript?

TypeScript adds typing to JavaScript.

What is typing? It’s a means to declare the type of a value/function/etc.

This means that, by declaring the expected type, we can determine if the value we’re passing to a function is valid or not. This allows us to find errors earlier (compile time) vs. when we run the app (run time).

TypeScript has two parts:

Pros of TypeScript in React Native

So, why use TypeScript?

Cons of TypeScript in React Native

Why not use TypeScript?

How to Use TypeScript in a React Native App

So, I’ve decided I want to create a React Native app and use TypeScript. How do I do it?

npx react-native init MyApp --template react-native-template-typescript

Yeah, that’s it… The React Native community has setup a template to use TypeScript in React Native.

If you’re using Expo just select one of their TypeScript templates when setting up your project.

Initial setup on a new app is definitely not a reason to avoid using TypeScript in React Native.

The React Native Docs have an entire page dedicated to using TypeScript in React Native (including how to add it to an existing project).

Final Thoughts

Look, I’ll be honest with you, I’m a lazy programmer.

I’m a firm believer of “if it ain’t broke, don’t fix it.”

And, generally, I’m happy with my workflow.

BUT…

I think I’ve put off this decision for a long enough and just reading about TypeScript isn’t enough. I want to use it in a real project.

So the next major app I work on (looking at a large trivia app example for React Native School) I’m going to use TypeScript to get a better grasp on it.

Resources

Are you all in on TypeScript? What improvements has it made to your workflow? What about challenges?

Originally published at https://www.reactnativeschool.com.

React Native School

Learn to build great React Native apps.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store