You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/0894-deprecate-subpath-imports.md
+70-1Lines changed: 70 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -84,7 +84,7 @@ import {Alert, AlertType} from 'react-native';
84
84
85
85
By removing subpath imports, we will scope the `react-native` package down to a narrower, enumerable public API, using the existing `index.js` and `index.d.ts` exports as a starting point.
86
86
87
-
All existing APIs exported from the main `'react-native'` import path will be **unchanged**. As of March 2025, we now define a strict list of type exports, see [`index.js.flow`](/TODO) — symbols that are not in this file will not be part of the public API.
87
+
All existing APIs exported from the main `'react-native'` import path will be **unchanged**. As of March 2025, we now define a strict list of type exports, see [`index.js.flow`](https://github.com/facebook/react-native/blob/main/packages/react-native/index.js.flow) — symbols that are not in this file will not be part of the public API.
88
88
89
89
#### Framework considerations
90
90
@@ -141,6 +141,10 @@ import {Alert} from 'react-native/Libraries/Alert/Alert';
141
141
142
142
**Under the hood**: As we are unsure about the % usage of [@react-native/eslint-config](https://www.npmjs.com/package/@react-native/eslint-config), we believe integrating via Metro is important for consistent visibility.
143
143
144
+
#### Removing subpaths from our TypeScript API (opt-in)
145
+
146
+
See [Parallel effort: Strict TypeScript API](#parallel-effort-strict-typescript-api).
147
+
144
148
### Eventual strong enforcement
145
149
146
150
Again, it's important that we give the community sufficient time to adapt to this change before we action a hard removal — we anticipate this will be during **H2 2025**.
@@ -159,3 +163,68 @@ This will functionally disallow unlisted subpath imports under TypeScript, Metro
159
163
}
160
164
}
161
165
```
166
+
167
+
---
168
+
169
+
## Parallel effort: Strict TypeScript API
170
+
171
+
> 🟢 In active development as of January 2025.
172
+
173
+
#### Discouraging use by removing subpaths under TypeScript
174
+
175
+
A parallel part of our adoption strategy is a new version of React Native's TypeScript API, auto-translated from the source codebase in Flow. While a separate effort, this forms an incentivising mechanism for removing subpath imports, on top of console and ESLint warnings.
176
+
177
+
This new API will no longer expose internal `react-native` modules under TypeScript — resulting in type errors against existing uses, and preventing new deep imports which may have occurred from auto-importing in the past.
178
+
179
+
#### User opt-in
180
+
181
+
By default, TypeScript will continue to use the existing manually defined types included in the `react-native` package, which allow subpaths.
182
+
183
+
When we ship the new Strict TypeScript API, it will be available as a user opt-in — by specifying the `"react-native-strict-api"` condition in a project's `tsconfig.json`.
Under the hood, this opt-in will be implemented in React Native via a lenient `package.json``"exports"` mapping, exposing only `"." → "types_generated/index.d.ts"` under this condition.
- The scope of this opt-in will be for the immediately analysed TypeScript project root, and will have no impact at runtime or on dependent projects.
214
+
- Having an user opt-in will be necessary both for subpath import removal, as well as breaking changes to some type shapes now generated from source (increasing correctness, consistency, and ergonomics).
215
+
- As with subpath import deprecation, we may consider an escape hatch for Frameworks, based on feedback.
216
+
217
+
#### Final state (coordinated removal of subpath imports)
218
+
219
+
The final state (potentially with a preceding opt-out state) will be a hard rollout of the new types in a future version of React Native, aligned with when we remove subpath imports in our `"exports"` mapping.
0 commit comments