-
Notifications
You must be signed in to change notification settings - Fork 24.3k
React Native TypeScript Maintenance
Many users in the React Native community use TypeScript in their projects. Because Meta engineers work primarily in Flow, the React Native JavaScript codebase is type-checked in Flow by default. To supplement, there is a TypeScript library definition for React Native.
For React Native 0.71 and lower, the TypeScript definitions are supplied via @types/react-native.
In React Native 0.71, we have started migrating the TypeScript definitions to be released with the react-native
package and to replace @types/react-native for versions 0.72 and above. This means one less dependency required.
To ensure TypeScript types accurately reflect the React Native codebase, there has been work by our partners to generate TS declarations from Flow declarations. See work in flow2dts. This work is still in development and cannot currently be used.
To mitigate in this interim, the React Native team is adding Flow declarations and nomenclature to signal when Flow types have been updated and ensuring our tooling properly alerts us.
As part of this you'll see the following nomenclature:
-
<FILENAME>.flow.js
- These are files that only contain types and no JS implementation -
<FILENAME>.js.flow
- These are Flow declarations that shadow the JS implementation ofFILENAME
and defines the types of the module.
Please add the following docblock to any added js.flow
files:
/**
* This is a Flow declaration file and defines the types for <YOUR_FILENAME>.*.js
* See https://github.com/facebook/react-native/wiki/React-Native-TypeScript-Maintenance
* for more details
*/
and for flow.js
files:
/**
* This is .flow.js file and should only export Flow types
* See https://github.com/facebook/react-native/wiki/React-Native-TypeScript-Maintenance
* for more details
*/
-
FILENAME.js.flow
is specifically a Flow declaration and refer to this file as the types forFILENAME.js
. Learn more here. These files are not included in our npm package. -
<FILENAME>.flow.js
is a simply a pattern our team devised to signal that a certain file should only contain types. These exist throughout React Native, say as the props of our core components likeViewProps.js
. We could have created aViewProps.js.flow
that declares the types the types that we're exposing inViewProps.js
-- however this felt like un-unnecessary bloat. In addition, React Native supports platform branching via*.<platform>.js
. If we lived in a world where we hadViewProps.android.js
andViewProps.ios.js
-- we'd need to create the equivalent*.js.flow
files which gets quite redundant.
React Native • Contributor Guide • Getting Started • Website
How to Contribute
- How to File an Issue ↗
- Triaging GitHub Issues ↗
- How to Label an Issue ↗
- Managing Pull Requests ↗
- How to Contribute Code ↗
- How to Open a Pull Request ↗
- How to Build from Source ↗
Tests
Releases
More Resources
- Contributor Guide ↗
- Code of Conduct ↗
- Contributor License Agreement ↗
- Discussions and Proposals ↗
- Bots Reference ↗
Documentation