question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Migrating the RN template to Typescript

See original GitHub issue

This issue wants to coordinate the conversation around the existing default template that is used when doing npx react-native init.

Context

It seems that the “inciting incident” for this conversation was a report by someone about the fact that the current templates “contains” some Flow typing https://github.com/facebook/react-native/issues/31936.

Flow is the JS typing of choice at FB, but not as much used anymore in the broader community. This has led @safaiyeh to offer to remove them, which evolved in a conversation which led to this issue.

Current status

Currently, the React Native CLI command init uses by default the template found in this repo (here) as blueprint to generate the project. As indicated above, it indeeds contains some Flow typing.

There is an optional template for Typescript already maintained in the RNC github org: https://github.com/react-native-community/react-native-template-typescript which is also documented in the docs.

That said, the TS typings are maintained separately in the DefinitelyTyped repo. We are not aware (as of now) of any one specific person maintaining them.

Proposal

Given how Typescript is very widely used in the Javascript world, it was proposed to replace the existing template with the ts-based one. Which should basically boil down to

We can do these and leave the file extension as .js, which makes it easy for both vanilla JS users and TS users.

This would mean that, by default (in an hypothetical future, >= 0.66) folks doing npx react-native init would get newly generated projects already set up for Typescript.

It would also mean (I think?) that the separate repo would get discontinued in favour of the folder within the main react-native repo (this one).

Concern

In discussing this option, one main concern surfaced: @types/react-native is currently not maintained in sync with the core repo. In particular, typings live in an external repo outside of the monorepo requires waiting for someone else to review to land.

That said:

  • it should(could?) be addressable
  • There is some longer term work to generate the TS typings dynamically, which would remove the need for someone to manually put in effort to update them.
  • currently the template is not tested (AFAIK) in any CI, so there’s no actual blocker to day-to-day development, it would only be a “manual” effort to update the types during a release process
  • it looks like it should be possible to have some test/pre-release types being set up if the template would start to be tested on CI
  • as per mention above, making the TS template the default would “add work” to the release process in the RC phase. (but it sounds reasonable to have to handle it)

pinging folks who were involved in the earlier conversations: @NickGerleman, @acoates-ms, @safaiyeh, @radko93, @satya164, @TheSavior

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
safaiyehcommented, Aug 5, 2021

Thanks for setting up the issue. I’ll be looking into this the next couple of days to propose a change to the template.

2reactions
ravirajn22commented, Aug 4, 2021

Why can’t we just make the init template pure JS, let the consumer decide later what he wants, typescript or flow or pure JS. Why do we want to complicate stuffs?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating the RN template to Typescript - GitHub
A framework for building native applications using React - Migrating the RN template to Typescript · facebook/react-native@472d531.
Read more >
Using TypeScript - React Native
If you're starting a new project, there are a few different ways to get started. You can use the TypeScript template: npx react-native...
Read more >
Documentation - Migrating from JavaScript - TypeScript
How to migrate from JavaScript to TypeScript. ... This is a common pattern people use to make their modules immediately callable like in...
Read more >
Migrating a 50K SLOC Flow + React Native app to TypeScript
Converting a Flow + React Native project to TypeScript, including motivations, helpful commands, conversion tips, and overall experience.
Read more >
Using TypeScript - Expo Documentation
The easiest way to get started is to initialize your new project using a TypeScript template, then run yarn tsc or npx tsc...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found