Skip to content

Commit 431ea7c

Browse files
committed
Enable Strict TS API by default (#57490)
Summary: Pull Request resolved: #57490 See [**RFC0894: Removing deep imports from react-native**](react-native-community/discussions-and-proposals#894) This is the **big switch** to enable the Strict TypeScript API (generated types + single index entry point) by default in React Native. **Opt-in → opt-out** After this change, the main `react-native` package resolves its `"types"` entry points only to `types_generated/index.d.ts` — with no other subpaths available. The new `"react-native-legacy-deep-imports"` condition maps to legacy `types/` and `Libraries/*.d.ts` sources. **Impact limitation**: For this stage of rollout, the `"default"` condition continues to resolve to source files. Only TypeScript is affected. **How to opt out** Opposite of today's opt-in, which we will update in [the docs](https://reactnative.dev/docs/strict-typescript-api). Again, the only impact area today is **TypeScript**. ```json5 // tsconfig.json { "extends": "react-native/typescript-config", "compilerOptions": { ... "customConditions": ["react-native-legacy-deep-imports"] } } ``` **Other changes** - Drop `react-native/typescript-config/strict` entry point, update README. - Update `__typetests__`. **Rollout plan** **Target release: 0.87**. This and the contributing stack will be cherry picked for RC1. - We've conducted testing against 100+ real Expo codebases, giving us the confidence that we've reduced breaking changes enough that the vast majority of RN codebases can migrate. - The Strict API includes a number of **intentional breaking changes**, and docs have been kept up to date. - We're shipping a `/migrate-to-strict-api` skill to migrate via agents, see react-native-community/skills#3. **What's improved since 0.80?** Since the initial opt-in launch of the Strict API in 0.80, we've been making continuous improvements over the last year to get our generated types into a widely launchable state. Most notably: - 21+ new/updated root APIs and fixes due to community feedback ([discussion](react-native-community/discussions-and-proposals#893), [PRs](https://github.com/react/react-native/pulls?q=is%3Apr%20label%3A%22JS%20API%20stabilization%20(1.0)%22%20is%3Aclosed)). - Upstream encapsulation blocker in TypeScript, fixed in 6.0 (#53565). - Tailwind/Uniwind compatibility (`interface` types for props). - `*Instance` ref type exports for all built-in components (react-native-community/discussions-and-proposals#1003). - Fixes to previously mistyped, high impact APIs, such as `Appearance`. - New subpath entry points for `asset-registry`, `setup-env`, and others. - Refinements to doc comments/type translation build. **Rollback plan** Revert this diff. IMPORTANT: We'll adopt a policy of **super-eager rollback**, if there are any unsolvable issues during the RC phase. Changelog: [General][Breaking] - React Native's default JavaScript API is now the [Strict TypeScript API](https://reactnative.dev/docs/strict-typescript-api). Use `customConditions: ["react-native-legacy-deep-imports"]` to opt out. Reviewed By: cortinico Differential Revision: D110458670 fbshipit-source-id: 4b0e0b458a5f895f783d6d936e7b11ccff2df076
1 parent ee26e3d commit 431ea7c

12 files changed

Lines changed: 34 additions & 75 deletions

File tree

.github/workflows/test-all.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,9 @@ jobs:
471471
- name: Flow
472472
shell: bash
473473
run: yarn flow-check
474-
- name: TypeScript
474+
- name: TypeScript (legacy deep imports / manual types)
475475
shell: bash
476-
run: yarn test-typescript
476+
run: yarn test-typescript-legacy
477477

478478
test_js:
479479
runs-on: ubuntu-latest

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"test-release-local-clean": "node ./scripts/release-testing/test-release-local-clean.js",
3434
"test-release-local": "node ./scripts/release-testing/test-release-local.js",
3535
"test-ios": "./scripts/objc-test.sh test",
36-
"test-typescript": "tsc -p packages/react-native/types/tsconfig.json",
37-
"test-generated-typescript": "tsc -p packages/react-native/types_generated/tsconfig.test.json",
36+
"test-typescript-legacy": "tsc -p packages/react-native/__typetests__/tsconfig.legacy.json",
37+
"test-generated-typescript": "tsc -p packages/react-native/__typetests__/tsconfig.json",
3838
"test": "jest",
3939
"fantom": "./scripts/fantom.sh",
4040
"fantom-cli": "./scripts/fantom-cli.sh",
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
23
"compilerOptions": {
34
"module": "esnext",
45
"lib": ["es2020"],
@@ -9,9 +10,7 @@
910
"jsx": "react",
1011
"noEmit": true,
1112
"forceConsistentCasingInFileNames": true,
12-
"paths": {"react-native": ["."]},
13-
"moduleResolution": "bundler",
14-
"customConditions": ["react-native-strict-api"]
13+
"moduleResolution": "bundler"
1514
},
16-
"include": ["**/*.d.ts", "../__typetests__/**/*"]
15+
"include": ["**/*"]
1716
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
// Legacy variant: Opts into the `"react-native-legacy-deep-imports"` export
4+
// condition so `react-native` and `react-native/Libraries/*` resolve to the
5+
// hand-written types in `types/`.
6+
"extends": "./tsconfig.json",
7+
"compilerOptions": {
8+
"customConditions": ["react-native-legacy-deep-imports"]
9+
}
10+
}

packages/react-native/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,19 @@
2727
"react-native": "cli.js"
2828
},
2929
"main": "./index.js",
30-
"types": "types",
3130
"exports": {
3231
".": {
33-
"react-native-strict-api": "./types_generated/index.d.ts",
34-
"types": "./types/index.d.ts",
32+
"react-native-legacy-deep-imports": "./types/index.d.ts",
33+
"types": "./types_generated/index.d.ts",
3534
"default": "./index.js"
3635
},
3736
"./Libraries/*": {
38-
"react-native-strict-api": null,
39-
"types": "./Libraries/*.d.ts",
37+
"react-native-legacy-deep-imports": "./Libraries/*.d.ts",
38+
"types": null,
4039
"default": "./Libraries/*.js"
4140
},
4241
"./Libraries/*.js": {
43-
"react-native-strict-api": null,
42+
"types": null,
4443
"default": "./Libraries/*.js"
4544
},
4645
"./scripts/*": "./scripts/*",

packages/react-native/types/tsconfig.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/typescript-config/README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,18 @@ This package provides the default `tsconfig.json` used by newly built React Nati
99

1010
This template is customized for specific versions of React Native, and should be updated in sync with the rest of your app.
1111

12-
## Strict TypeScript API
12+
## Opting out of the Strict TypeScript API (default in 0.87)
1313

14-
To opt into the new [strict TypeScript API](https://reactnative.dev/blog/2025/06/12/moving-towards-a-stable-javascript-api#strict-typescript-api-opt-in) you can extend from `@react-native/typescript-config/strict`
14+
To opt out of the new [Strict TypeScript API](https://reactnative.dev/docs/strict-typescript-api) you can extend from `@react-native/typescript-config/strict`
1515

16-
```jsonc
17-
{
18-
"extends": "@react-native/typescript-config/strict",
19-
// ...
20-
}
21-
```
22-
23-
or alternatively add the `customConditions` yourself:
16+
If your app still needs access to deep `'react-native/Libraries/*'` imports (deprecated in 0.80), you can opt out via `customConditions` in your `tsconfig.json`:
2417

2518
```jsonc
2619
{
2720
"extends": "@react-native/typescript-config",
2821
"compilerOptions": {
2922
// ...
30-
"customConditions": ["react-native-strict-api", "react-native"]
23+
"customConditions": ["react-native", "react-native-legacy-deep-imports"]
3124
}
3225
}
3326
```

packages/typescript-config/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
],
1717
"bugs": "https://github.com/react/react-native/issues",
1818
"exports": {
19-
".": "./tsconfig.json",
20-
"./strict": "./tsconfig.strict.json"
19+
".": "./tsconfig.json"
2120
}
2221
}

packages/typescript-config/tsconfig.strict.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

packages/virtualized-lists/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
},
2222
"exports": {
2323
".": {
24-
"react-native-strict-api": "./types_generated/index.d.ts",
25-
"types": "./index.d.ts",
24+
"react-native-legacy-deep-imports": "./index.d.ts",
25+
"types": "./types_generated/index.d.ts",
2626
"default": "./index.js"
2727
},
2828
"./*": {

0 commit comments

Comments
 (0)