Skip to content

Commit

Permalink
Better TypeScript support for package.json exports field (#37377)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #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: microsoft/TypeScript#51669

Changelog:
[General][Added] - Better TypeScript support for package.json exports field

Reviewed By: christophpurrer

Differential Revision: D45769740

fbshipit-source-id: 1ad450b8157bfd0d539289835bed097fd950cf78
  • Loading branch information
NickGerleman authored and facebook-github-bot committed May 13, 2023
1 parent 61335a1 commit 1b0e8b1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/typescript-config/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"display": "React Native",
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"module": "es2015",
"types": ["react-native", "jest"],
"lib": [
"es2019",
Expand All @@ -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,
Expand Down

1 comment on commit 1b0e8b1

@Yupeng-li
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it right to set module to es2015? From this doc, it seems the module has to be either esnext or preserve when moduleResolution is set to bundler.

Please sign in to comment.