From 1b0e8b1de470bd5501d78defce6ad6fe4b2ade4b Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Sat, 13 May 2023 09:38:17 -0700 Subject: [PATCH] Better TypeScript support for package.json exports field (#37377) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37377 For 0.72 I enabled `moduleResolution: "nodenext"` which allows some package exports support, but this is imperfect. E.g. RN will typecheck against the `node` condition and there are some more restrictions than we need. D45720238 bumped TypeScript to 5.0 for RN 0.73, along with D45721088 which brought the tsconfig inline. This lets us switch to the new [`moduleResolution: "bundler"`](https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#moduleresolution-bundler) and instructs `tsc` to follow the `react-native` export condition. See even more context at: https://github.com/microsoft/TypeScript/pull/51669 Changelog: [General][Added] - Better TypeScript support for package.json exports field Reviewed By: christophpurrer Differential Revision: D45769740 fbshipit-source-id: 1ad450b8157bfd0d539289835bed097fd950cf78 --- packages/typescript-config/tsconfig.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/typescript-config/tsconfig.json b/packages/typescript-config/tsconfig.json index 06686519903f5d..3bb1451e792d9a 100644 --- a/packages/typescript-config/tsconfig.json +++ b/packages/typescript-config/tsconfig.json @@ -3,7 +3,7 @@ "display": "React Native", "compilerOptions": { "target": "esnext", - "module": "commonjs", + "module": "es2015", "types": ["react-native", "jest"], "lib": [ "es2019", @@ -25,8 +25,12 @@ "noEmit": true, "isolatedModules": true, "strict": true, - "moduleResolution": "nodenext", + "moduleResolution": "bundler", + "customConditions": ["react-native"], + "allowImportingTsExtensions": true, + "allowArbitraryExtensions": true, "resolveJsonModule": true, + "resolvePackageJsonImports": false, "allowSyntheticDefaultImports": true, "esModuleInterop": true, "skipLibCheck": true,