Skip to content

Commit da00fc8

Browse files
huntiefacebook-github-bot
authored andcommitted
Enable Strict TS API by default (#57490)
Summary: See [**RFC0894: Removing deep imports from react-native**](react-native-community/discussions-and-proposals#894) TODO: Description to come. Differential Revision: D110458670
1 parent 5663743 commit da00fc8

13 files changed

Lines changed: 50 additions & 88 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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
// Default config: resolves `react-native` through the package `exports` map,
4+
// which selects the Strict API (`types_generated/`). `tsconfig.legacy.json`
5+
// opts back into the legacy deep-import types.
6+
"compilerOptions": {
7+
"module": "esnext",
8+
"lib": ["es2020"],
9+
"strict": false,
10+
"noImplicitAny": true,
11+
"noImplicitThis": true,
12+
"types": [],
13+
"jsx": "react",
14+
"noEmit": true,
15+
"forceConsistentCasingInFileNames": true,
16+
"moduleResolution": "bundler"
17+
},
18+
"include": ["**/*"]
19+
}
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.78)
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 into 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-legacy-deep-imports", "react-native"]
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)