Skip to content

Conversation

@kraenhansen
Copy link
Contributor

@kraenhansen kraenhansen commented Sep 2, 2025

Summary:

Extending a tsconfig seems simpler than adding compilerOptions with customConditions.

Before

{
  "extends": "@react-native/typescript-config",
  "compilerOptions": {
    // ...
    "customConditions": ["react-native-strict-api", "react-native"]
  }
}

After

{
  "extends": "@react-native/typescript-config/strict"
  // ...
}

Changelog:

[GENERAL] [ADDED] - Add @react-native/typescript-config/strict export enabling the react-native-strict-api custom condition.

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/index.d.ts@0.81.1+react@19.1.1'. ======== 

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 2, 2025
@kraenhansen kraenhansen marked this pull request as ready for review September 18, 2025 06:37
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 18, 2025
@facebook-github-bot
Copy link
Contributor

@philIip has imported this pull request. If you are a Meta employee, you can view this in D82791201.

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Sep 19, 2025
@facebook-github-bot
Copy link
Contributor

@philIip merged this pull request in 0198c92.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @kraenhansen in 0198c92

When will my fix make it into a release? | How to file a pick request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants