diff --git a/.github/workflows/test-all.yml b/.github/workflows/test-all.yml index 422a90c712a..1f49896cbf3 100644 --- a/.github/workflows/test-all.yml +++ b/.github/workflows/test-all.yml @@ -471,9 +471,9 @@ jobs: - name: Flow shell: bash run: yarn flow-check - - name: TypeScript + - name: TypeScript (legacy deep imports / manual types) shell: bash - run: yarn test-typescript + run: yarn test-typescript-legacy test_js: runs-on: ubuntu-latest diff --git a/package.json b/package.json index a61c4174102..49e5e3a9bc2 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,8 @@ "test-release-local-clean": "node ./scripts/release-testing/test-release-local-clean.js", "test-release-local": "node ./scripts/release-testing/test-release-local.js", "test-ios": "./scripts/objc-test.sh test", - "test-typescript": "tsc -p packages/react-native/types/tsconfig.json", - "test-generated-typescript": "tsc -p packages/react-native/types_generated/tsconfig.test.json", + "test-typescript-legacy": "tsc -p packages/react-native/__typetests__/tsconfig.legacy.json", + "test-generated-typescript": "tsc -p packages/react-native/__typetests__/tsconfig.json", "test": "jest", "fantom": "./scripts/fantom.sh", "fantom-cli": "./scripts/fantom-cli.sh", diff --git a/scripts/js-api/build-types/templates/tsconfig.test.json b/packages/react-native/__typetests__/tsconfig.json similarity index 59% rename from scripts/js-api/build-types/templates/tsconfig.test.json rename to packages/react-native/__typetests__/tsconfig.json index 7af1dd074cb..241c3b969fb 100644 --- a/scripts/js-api/build-types/templates/tsconfig.test.json +++ b/packages/react-native/__typetests__/tsconfig.json @@ -1,4 +1,5 @@ { + "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { "module": "esnext", "lib": ["es2020"], @@ -9,9 +10,7 @@ "jsx": "react", "noEmit": true, "forceConsistentCasingInFileNames": true, - "paths": {"react-native": ["."]}, - "moduleResolution": "bundler", - "customConditions": ["react-native-strict-api"] + "moduleResolution": "bundler" }, - "include": ["**/*.d.ts", "../__typetests__/**/*"] + "include": ["**/*"] } diff --git a/packages/react-native/__typetests__/tsconfig.legacy.json b/packages/react-native/__typetests__/tsconfig.legacy.json new file mode 100644 index 00000000000..3aea5153dce --- /dev/null +++ b/packages/react-native/__typetests__/tsconfig.legacy.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + // Legacy variant: Opts into the `"react-native-legacy-deep-imports"` export + // condition so `react-native` and `react-native/Libraries/*` resolve to the + // hand-written types in `types/`. + "extends": "./tsconfig.json", + "compilerOptions": { + "customConditions": ["react-native-legacy-deep-imports"] + } +} diff --git a/packages/react-native/package.json b/packages/react-native/package.json index ef1824b3797..39cad31c687 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -27,20 +27,19 @@ "react-native": "cli.js" }, "main": "./index.js", - "types": "types", "exports": { ".": { - "react-native-strict-api": "./types_generated/index.d.ts", - "types": "./types/index.d.ts", + "react-native-legacy-deep-imports": "./types/index.d.ts", + "types": "./types_generated/index.d.ts", "default": "./index.js" }, "./Libraries/*": { - "react-native-strict-api": null, - "types": "./Libraries/*.d.ts", + "react-native-legacy-deep-imports": "./Libraries/*.d.ts", + "types": null, "default": "./Libraries/*.js" }, "./Libraries/*.js": { - "react-native-strict-api": null, + "types": null, "default": "./Libraries/*.js" }, "./scripts/*": "./scripts/*", diff --git a/packages/react-native/types/tsconfig.json b/packages/react-native/types/tsconfig.json deleted file mode 100644 index bb7659500b1..00000000000 --- a/packages/react-native/types/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": ["es6"], - "strict": false, - "noImplicitAny": true, - "noImplicitThis": true, - "strictFunctionTypes": true, - "strictNullChecks": true, - "types": [], - "jsx": "react", - "noEmit": true, - "forceConsistentCasingInFileNames": true, - "paths": {"react-native": ["."]} - }, - "include": ["**/*.d.ts", "../__typetests__/**/*"] -} diff --git a/packages/typescript-config/README.md b/packages/typescript-config/README.md index d58ee3b5645..bf53f0c39a6 100644 --- a/packages/typescript-config/README.md +++ b/packages/typescript-config/README.md @@ -9,25 +9,18 @@ This package provides the default `tsconfig.json` used by newly built React Nati This template is customized for specific versions of React Native, and should be updated in sync with the rest of your app. -## Strict TypeScript API +## Opting out of the Strict TypeScript API (default in 0.87) -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` +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` -```jsonc -{ - "extends": "@react-native/typescript-config/strict", - // ... -} -``` - -or alternatively add the `customConditions` yourself: +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`: ```jsonc { "extends": "@react-native/typescript-config", "compilerOptions": { // ... - "customConditions": ["react-native-strict-api", "react-native"] + "customConditions": ["react-native", "react-native-legacy-deep-imports"] } } ``` diff --git a/packages/typescript-config/package.json b/packages/typescript-config/package.json index a9bdc0e273b..5e2b217934d 100644 --- a/packages/typescript-config/package.json +++ b/packages/typescript-config/package.json @@ -16,7 +16,6 @@ ], "bugs": "https://github.com/react/react-native/issues", "exports": { - ".": "./tsconfig.json", - "./strict": "./tsconfig.strict.json" + ".": "./tsconfig.json" } } diff --git a/packages/typescript-config/tsconfig.strict.json b/packages/typescript-config/tsconfig.strict.json deleted file mode 100644 index c060fa2a419..00000000000 --- a/packages/typescript-config/tsconfig.strict.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "extends": "./tsconfig.json", - "display": "React Native (Strict)", - "compilerOptions": { - "customConditions": ["react-native-strict-api", "react-native"] - } -} diff --git a/packages/virtualized-lists/package.json b/packages/virtualized-lists/package.json index aca2c989aaf..4ce33c82110 100644 --- a/packages/virtualized-lists/package.json +++ b/packages/virtualized-lists/package.json @@ -21,8 +21,8 @@ }, "exports": { ".": { - "react-native-strict-api": "./types_generated/index.d.ts", - "types": "./index.d.ts", + "react-native-legacy-deep-imports": "./index.d.ts", + "types": "./types_generated/index.d.ts", "default": "./index.js" }, "./*": { diff --git a/scripts/js-api/build-types/buildGeneratedTypes.js b/scripts/js-api/build-types/buildGeneratedTypes.js index 1408b1625b5..3ef71abc2d1 100644 --- a/scripts/js-api/build-types/buildGeneratedTypes.js +++ b/scripts/js-api/build-types/buildGeneratedTypes.js @@ -55,26 +55,10 @@ async function buildGeneratedTypes(): Promise> { } } - await Promise.all([ - fs.copyFile( - path.join(__dirname, 'templates', 'tsconfig.json'), - path.join( - PACKAGES_DIR, - 'react-native', - TYPES_OUTPUT_DIR, - 'tsconfig.json', - ), - ), - fs.copyFile( - path.join(__dirname, 'templates', 'tsconfig.test.json'), - path.join( - PACKAGES_DIR, - 'react-native', - TYPES_OUTPUT_DIR, - 'tsconfig.test.json', - ), - ), - ]); + await fs.copyFile( + path.join(__dirname, 'templates', 'tsconfig.json'), + path.join(PACKAGES_DIR, 'react-native', TYPES_OUTPUT_DIR, 'tsconfig.json'), + ); if (allErrors.length > 0) { console.error( diff --git a/scripts/run-ci-javascript-tests.js b/scripts/run-ci-javascript-tests.js index 7992b46fbcc..aed03f7f812 100644 --- a/scripts/run-ci-javascript-tests.js +++ b/scripts/run-ci-javascript-tests.js @@ -81,7 +81,7 @@ try { ); describe('Test: TypeScript tests'); - execAndLog(`${YARN_BINARY} run test-typescript`); + execAndLog(`${YARN_BINARY} run test-typescript-legacy`); } catch (e) { if (e instanceof ExecError) { console.error(e.message);