Moving Towards a Stable JavaScript API in React Native
Article Summary
React Native 0.80 is making a bold move: deprecating deep imports and introducing auto-generated TypeScript types. This is the foundation for a truly stable API.
The React Native team at Meta is tackling a long-standing problem with their JavaScript API. Historically, types were manually maintained by the community and internal imports were accessible but unstable. Now they're drawing clear boundaries around what's public and what's private.
Key Takeaways
- Deep imports like 'react-native/Libraries/Alert/Alert' now trigger deprecation warnings
- New Strict TypeScript API generates types directly from Flow source code
- Opt-in via tsconfig.json with 'react-native-strict-api' custom condition
- Types now locked to index.js exports, preventing internal changes from breaking apps
- Removal of deep imports targeted for version 0.82
React Native is finally defining a stable public API by deprecating deep imports and offering auto-generated TypeScript types that guarantee accuracy with the source code.
About This Article
React Native's JavaScript API didn't have clear boundaries between public and internal code. Apps could import directly from react-native/Libraries/, but these internal paths changed frequently as the team updated the codebase, making apps break unexpectedly.
Meta's React Native team discouraged deep imports by adding ESLint rules and console warnings. They also generated TypeScript types from Flow source code that only expose what's in index.js, which prevents access to internal modules.
Changes inside React Native's codebase won't break apps anymore because the public API is now limited to what index.js exports. The team plans to remove deep imports entirely by version 0.82.