Migrating the RN template to Typescript
See original GitHub issueThis 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
- add a tsconfig
- add the typescript dependency to package.json
- add a dependency on @types/react and @types/react-native
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:
- Created 2 years ago
- Reactions:5
- Comments:10 (1 by maintainers)
Top GitHub Comments
Thanks for setting up the issue. I’ll be looking into this the next couple of days to propose a change to the template.
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?