Since React Native 0.87, a project type-checks against the Strict TypeScript API, which replaces the hand-maintained definitions of earlier versions. The switch is a breaking change, so upgrading an older app can turn a clean tsc run into a long list of errors. What it changes, and what it leaves alone, tells you which errors to fix in your code, which to fix by updating a dependency, and when the temporary opt-out is the right call.
Key terms
- Strict TypeScript API: React Native's TypeScript API generated from its source, on by default since 0.87 and opt-in from 0.80.
- Deep import: an import from a path inside the package, such as
react-native/Libraries/..., instead of fromreact-nativeitself. react-native-legacy-deep-imports: the TypeScript-only condition that switches a project back to the previous manual types.
Types come from the index file only
The first change is that there are no deep imports. The typed API is what react-native's index file exports, and nothing below it. The package's exports map shows how. For the root react-native import, types resolve to ./types_generated/index.d.ts. For react-native/Libraries/*, the types entry is null unless the legacy condition is set, while the JavaScript still resolves to ./Libraries/*.js. A deep import still runs, but TypeScript has no types for it.
The second change is where the types come from. types_generated/index.d.ts is generated from React Native's Flow entry file, index.js.flow. The old types were written by hand and came from @types/react-native on DefinitelyTyped.
When something you used to import is missing from the root export, that is usually on purpose. The RFC behind the Strict API scoped the public API to what the index file exports, so some internals that were reachable before are now private.
Only your project's types change
Turning on the Strict API affects only the TypeScript analysis of your own project, scoped by its tsconfig.json. Nothing changes at runtime: both modes resolve the same JavaScript, and your bundle is unaffected. Metro's React Native defaults resolve packages with the condition react-native only and never use the legacy condition. One unrelated 0.87 change does reach runtime: it removed react-native/src/private/* from the package exports.
Because each project opts in through its own tsconfig.json, apps and libraries migrate independently. Your app doesn't wait for its dependencies, and a library doesn't wait for its users, since consumers only see the type definitions a package ships.
When the errors come from a dependency
That independence relies on skipLibCheck, which the base config turns on. If your tsconfig.json sets it to false, turn it back on before you migrate, or you will see errors inside dependencies that you can't fix.
When a type error involves a library, first check for a fixed release and update to it. react-native-safe-area-context is one example: it fixed its Strict API rough edge in 5.8.1, and the template depends on ^5.5.2, so check the version your lockfile actually holds.
One case slips past skipLibCheck. Some libraries ship raw TypeScript source that your project imports, such as Jest setup files, and that source is type-checked as part of your project. If it uses deep imports and no fixed release exists, the errors appear under node_modules, typically as TS2307: Cannot find module 'react-native/Libraries/...'. The local fix is to redirect the imported subpath to an untyped stub with paths, then report the incompatibility to the library. The stub example below maps a mock entry point to untyped-module.d.ts, a file whose only export is a default of type unknown.
Opting out for now
React Native still ships the previous manual types, and a project can switch back to them in tsconfig.json:
json{ "extends": "@react-native/typescript-config", "compilerOptions": { "customConditions": ["react-native", "react-native-legacy-deep-imports"] } }
With that condition, the root import and deep imports resolve to the old definitions under types_DEPRECATED. A future release will remove the opt-out, so treat it as a way to ship an upgrade while the migration waits. Library authors are in the same position: migrate your own source, and make sure any raw TypeScript you ship for consumers, such as a Jest mock entry point, does not rely on deep imports.
Code Examples
{
"extends": "@react-native/typescript-config",
"compilerOptions": {
"paths": {
"legacy-calendar/jest/mock": ["./untyped-module.d.ts"]
}
},
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["**/node_modules", "**/Pods"]
}// untyped-module.d.ts
declare const anyExport: unknown;
export default anyExport;