Skip to content

Commit 0198c92

Browse files
kraenhansenfacebook-github-bot
authored andcommitted
Export @react-native/typescript-config/strict shorthand (#53564)
Summary: Extending a tsconfig seems simpler than adding `compilerOptions` with `customConditions`. ### Before ```jsonc { "extends": "react-native/typescript-config", "compilerOptions": { // ... "customConditions": ["react-native-strict-api", "react-native"] } } ``` ### After ```jsonc { "extends": "react-native/typescript-config/strict" // ... } ``` ## Changelog: [GENERAL] [ADDED] - Add `react-native/typescript-config/strict` export enabling the `react-native-strict-api` custom condition. Pull Request resolved: #53564 Test Plan: ### `package.json` ``` { "name": "react-native-ts-test", "private": true, "version": "0.1.0", "scripts": { "build": "tsc --noEmit" }, "devDependencies": { "react-native/typescript-config": "^0.81.1", "typescript": "^5.9.2", "jest": "^30.1.2" }, "dependencies": { "react-native": "^0.81.1" } } ``` ### `tsconfig.json` ``` { "extends": "react-native/typescript-config/strict", "include": ["src/index.ts"] } ``` ### `src/index.ts` ``` import { View } from "react-native"; ``` Run `npx resolution-explorer` and select "react-native from src/index.ts to node_modules/react-native/types_generated/index.d.ts" to verify the types are resolved correctly. ``` Explicitly specified module resolution kind: 'Bundler'. Resolving in CJS mode with conditions 'import', 'types', 'react-native-strict-api'. File '/Users/kraen.hansen/Repositories/react-native-ts-test/src/package.json' does not exist. Found 'package.json' at '/Users/kraen.hansen/Repositories/react-native-ts-test/package.json'. Loading module 'react-native' from 'node_modules' folder, target file types: TypeScript, JavaScript, Declaration, JSON. Searching all ancestor node_modules directories for preferred extensions: TypeScript, Declaration. Directory '/Users/kraen.hansen/Repositories/react-native-ts-test/src/node_modules' does not exist, skipping all lookups in it. Found 'package.json' at '/Users/kraen.hansen/Repositories/react-native-ts-test/node_modules/react-native/package.json'. Entering conditional exports. Matched 'exports' condition 'react-native-strict-api'. Using 'exports' subpath '.' with target './types_generated/index.d.ts'. File '/Users/kraen.hansen/Repositories/react-native-ts-test/node_modules/react-native/types_generated/index.d.ts' exists - use it as a name resolution result. 'package.json' has a 'peerDependencies' field. Resolving real path for '/Users/kraen.hansen/Repositories/react-native-ts-test/node_modules/react-native', result '/Users/kraen.hansen/Repositories/react-native-ts-test/node_modules/react-native'. Failed to find peerDependency 'types/react'. Found 'package.json' at '/Users/kraen.hansen/Repositories/react-native-ts-test/node_modules/react/package.json'. Found peerDependency 'react' with '19.1.1' version. Resolved under condition 'react-native-strict-api'. Exiting conditional exports. Resolving real path for '/Users/kraen.hansen/Repositories/react-native-ts-test/node_modules/react-native/types_generated/index.d.ts', result '/Users/kraen.hansen/Repositories/react-native-ts-test/node_modules/react-native/types_generated/index.d.ts'. ======== Module name 'react-native' was successfully resolved to '/Users/kraen.hansen/Repositories/react-native-ts-test/node_modules/react-native/types_generated/index.d.ts' with Package ID 'react-native/types_generated/[email protected][email protected]'. ======== ``` Reviewed By: robhogan Differential Revision: D82791201 Pulled By: philIip fbshipit-source-id: f58d3b8fcf3d7f18dd29eef18a3c8c0cb57d1d78
1 parent 34cd61f commit 0198c92

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

packages/typescript-config/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,26 @@
33
This package provides the default `tsconfig.json` used by newly built React Native apps.
44

55
This template is customized for specific versions of React Native, and should be updated in sync with the rest of your app.
6+
7+
## Strict TypeScript API
8+
9+
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`
10+
11+
```jsonc
12+
{
13+
"extends": "@react-native/typescript-config/strict",
14+
// ...
15+
}
16+
```
17+
18+
or alternatively add the `customConditions` yourself:
19+
20+
```jsonc
21+
{
22+
"extends": "@react-native/typescript-config",
23+
"compilerOptions": {
24+
// ...
25+
"customConditions": ["react-native-strict-api", "react-native"]
26+
}
27+
}
28+
```

packages/typescript-config/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@
1515
"react-native"
1616
],
1717
"bugs": "https://github.com/facebook/react-native/issues",
18-
"main": "tsconfig.json"
18+
"exports": {
19+
".": "./tsconfig.json",
20+
"./strict": "./tsconfig.strict.json"
21+
}
1922
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"extends": "./tsconfig.json",
4+
"display": "React Native (Strict)",
5+
"compilerOptions": {
6+
"customConditions": ["react-native-strict-api", "react-native"]
7+
}
8+
}

0 commit comments

Comments
 (0)