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
Specifically, this is a new set of TypeScript types for the `react-native`npm package, available from 0.80 onwards. These provide stronger and more futureproof type accuracy, and will allow us to confidently evolve React Native's API into a stable shape. Opting in to the Strict TypeScript API brings some structural type differences, and is therefore a one-time breaking change.
12
+
The Strict TypeScript API is a new set of TypeScript types for the `react-native` package, providing a refined single package entry point and stronger type accuracy.
11
13
12
-
The new types are:
13
-
14
-
1.**Generated directly from our source code** — improving coverage and correctness, so you can expect stronger compatibility guarantees.
15
-
2.**Restricted to `react-native`'s index file** — more tightly defining our public API, and meaning we won't break the API when making internal file changes.
16
-
17
-
When the community is ready, the Strict TypeScript API will become our default API in future — synchronized with deep imports removal.
14
+
The Strict API is currently in preview as we iterate towards a stable JavaScript API for React Native.
18
15
19
16
## Opting in
20
17
21
-
We're shipping these new types alongside our existing types,meaning you can choose to migrate when ready. We encourage early adopters and newly created apps to opt in via your `tsconfig.json`file.
18
+
We're shipping these new types alongside our existing types,meaning you can choose to migrate when ready, via your `tsconfig.json`config.
22
19
23
-
Opting in is a **breaking change**, since some of our new types have updated names and shapes, although many apps won't be affected. You can learn about each breaking change in the next section.
20
+
Opting in brings some structural type differences, including updated type names and shapes. Therefore migrating your codebase to the Strict API is a **one-time breaking change**.
24
21
25
22
```json title="tsconfig.json"
26
23
{
@@ -38,25 +35,31 @@ This will instruct TypeScript to resolve `react-native` types from our new [`typ
38
35
39
36
:::
40
37
41
-
The Strict TypeScript API follows our [RFC](https://github.com/react-native-community/discussions-and-proposals/pull/894) to remove deep imports from React Native. Therefore, some APIs are no longer exported at root. This is intentional, in order to reduce the overall surface area of React Native's API.
38
+
### Key changes (breaking)
42
39
43
-
:::tip[API feedback]
40
+
1.**No deep imports.** The API is restricted to `react-native`'s index file. This is a tighter and more intentional public API contract. It also ensures that internal file path changes in React Native's source code won't be breaking.
41
+
2.**Generated directly from source.** Previously, React Native used separately maintained manual types. Generating from source now means we improve coverage, correctness, and compatibility guarantees.
44
42
45
-
**Sending feedback**: We will be working with the community to finalize which APIs we export over (at least) the next two React Native releases. Please share your feedback in our [feedback thread](https://github.com/react-native-community/discussions-and-proposals/discussions/893).
43
+
---
46
44
47
-
See also our [announcement blog post](/blog/2025/06/12/moving-towards-a-stable-javascript-api) for more info on our motivation and timelines.
45
+
:::tip[Preview feedback]
46
+
47
+
We're working with the community and partners to finalize the shape of the Strict API. Share API feedback in our [discussion thread](https://github.com/react-native-community/discussions-and-proposals/discussions/893), or see the [announcement blog post](/blog/2025/06/12/moving-towards-a-stable-javascript-api) for more context.
48
48
49
49
:::
50
50
51
51
## Migration guide
52
52
53
-
### Codegen types should now be imported from the `react-native` package
53
+
### Codegen types → `CodegenTypes` namespace
54
54
55
55
Types used for codegen, like `Int32`, `Double`, `WithDefault` etc. are now available under a single `CodegenTypes` namespace. Similarly, `codegenNativeComponent` and `codegenNativeCommands` are now available to import from the react-native package instead of using the deep import.
56
56
57
57
Namespaced `CodegenTypes` as well as `codegenNativeCommands` and `codegenNativeComponent` are also available from `react-native` package when the Strict API is not enabled to make the adoption easier for third-party libraries.
Each built-in component now has a dedicated `*Instance` type for use with refs — for example, `ViewInstance`, `TextInputInstance`, `ScrollViewInstance`. These are the **recommended way to type refs** under the Strict TypeScript API.
103
+
104
+
Previously, `useRef<View>` worked because `View` and other components were typed as a class. Under the Strict API, built-in components are typed as functions, so `View` refers to the function itself — **component type names no longer work as ref types**.
`*Instance` types also work transparently with `Animated` variants — no separate type is needed:
150
+
151
+
```tsx title=""
152
+
const viewRef =useRef<ViewInstance>(null);
153
+
154
+
<Viewref={viewRef} />
155
+
<Animated.Viewref={viewRef} />
156
+
```
157
+
158
+
This also replaces the removed `Animated.LegacyRef` type. Code using `ref={ref as React.Ref<Animated.LegacyRef<View>>}` can be simplified to `ref={ref}` with a `ViewInstance`-typed ref.
159
+
160
+
<details>
161
+
<summary>**🗒️ Available instance types**</summary>
`React.ComponentRef<typeof View>` remains valid and produces the same type as `ViewInstance`. The `*Instance` types are convenient aliases — both approaches work.
@@ -101,7 +220,8 @@ function foo(linking: LinkingStatic) {}
101
220
foo(Linking);
102
221
```
103
222
104
-
**After**
223
+
</TabItem>
224
+
<TabItemvalue="after"label="After">
105
225
106
226
```tsx title=""
107
227
import {Linking} from'react-native';
@@ -110,11 +230,13 @@ function foo(linking: Linking) {}
110
230
foo(Linking);
111
231
```
112
232
113
-
The following APIs were previously named as `*Static` plus a variable declaration of said type. In most cases there was an alias so that value and the type were exported under the same identifier, but some were missing.
233
+
</TabItem>
234
+
</Tabs>
114
235
115
-
(For example there was an `AlertStatic` type, `Alert`variable of type`AlertStatic` and type `Alert` which was an alias for `AlertStatic`. But in the case of `PixelRatio` there was a `PixelRatioStatic`type and a `PixelRatio` variable of that type without additional type aliases.)
236
+
The following APIs were previously named as `*Static` plus a variable declaration of said type. In most cases there was an alias so that value and the type were exported under the same identifier, but some were missing.
116
237
117
-
**Affected APIs**
238
+
<details>
239
+
<summary>**🗒️ Affected APIs**</summary>
118
240
119
241
-`AlertStatic`
120
242
-`ActionSheetIOSStatic`
@@ -145,34 +267,15 @@ The following APIs were previously named as `*Static` plus a variable declaratio
145
267
-`SettingsStatic`
146
268
-`VibrationStatic`
147
269
148
-
### Some core components are now function components instead of class components
149
-
150
-
-`View`
151
-
-`Image`
152
-
-`TextInput`
153
-
-`Modal`
154
-
-`Text`
155
-
-`TouchableWithoutFeedback`
156
-
-`Switch`
157
-
-`ActivityIndicator`
158
-
-`ProgressBarAndroid`
159
-
-`InputAccessoryView`
160
-
-`Button`
161
-
-`SafeAreaView`
162
-
163
-
Due to this change, accessing ref types of these views requires using `React.ComponentRef<typeof View>` pattern which works as expected for both class and function components, e.g.:
0 commit comments