Align SDK tsconfig lib with React Native - #64
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
All reviewed changes are focused and no unresolved issues were identified.
Review effort: Balanced
Findings: None
What changed in this PR
Aligns the SDK’s TypeScript build with React Native 0.76 runtime APIs while preventing ambient Node typings from widening available globals.
Changes:
- Matches React Native’s supported ES libraries.
- Disables automatic
@types/*inclusion. - Adds a narrow
consoledeclaration.
| File | Description |
|---|---|
tsconfig.build.json |
Restricts TypeScript libraries and ambient types. |
src/globals.d.ts |
Declares the required React Native console global. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| "es2020.bigint", | ||
| "es2020.date", | ||
| "es2020.number", | ||
| "es2020.promise", | ||
| "es2020.string", | ||
| "es2020.symbol.wellknown", | ||
| "es2021.promise", | ||
| "es2021.string", | ||
| "es2021.weakref", | ||
| "es2022.array", | ||
| "es2022.object", | ||
| "es2022.string" |
There was a problem hiding this comment.
Do we use any of these? We can handpick the ones we want to use in the SDK, and what RN support. The SDK can be stricter than RN!
If we dont use anything from this big list, simply keep our list simple as can be: [es2019] for example.
And I would keep a link to the RN's list of the minimum supported version for sure, for easier lookup if we ever want to widen it.
There was a problem hiding this comment.
|
@ofalvai Additional questions:
|
If you mean polyfill support, then yes. Perfect example from my main PR: https://github.com/bitrise-io/react-native-code-push/pull/63/changes#diff-3846a333c5be87762e72c131ab62f5015d1777f1c6c00fa4af419f07dc0dc6bfR294-R296
At the moment, we don't. I think we can be generous and support old versions as long as it doesn't have too much of an overhead for us, and decide case-by-case.
It comes from README.md and from the pre-fork state of things. Adding support for RN New Architecture meant breaking changes, so that first verison of the SDK cut support for older RN versions.
Definitely, 0.76 is now 2 years old, I think we can start bumping this, but it's hard to say how aggressively. |
tsconfig.build.json declared only the es6 lib, but it had no "types" setting, so TypeScript loaded every @types/* package. @types/node then added its own ES2018 libs and Node globals, which made the lib setting meaningless: code could use APIs outside it and still compile. Use lib es2019, a subset of the lib list in @react-native/typescript-config@0.76.0 (the oldest supported RN version), and set "types": [] so that lib is enforced. The SDK can be stricter than RN: es2019 covers everything it uses today, and it can be widened as far as RN's list when needed. The one runtime global the SDK needs, console, is declared in src/globals.d.ts until the build can use "types": ["react-native"] like the official config (needs TypeScript 5 and bundler module resolution, since RN exposes its types only through package.json "exports"). The emitted lib/ output does not change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
64395e6 to
c93b49a
Compare
Why
tsconfig.build.jsondeclares only thees6lib, but it has notypessetting. So TypeScript loads every@types/*package innode_modules, and@types/nodeadds its own ES2018 libs and Node globals. Thelibsetting has no effect. Code can use APIs outside it and still compile.This came up in #63, which uses
Object.entries(ES2017). That build passed only because of@types/node. This PR fixes the config first, and #63 builds on top of it.What changes
libis now the list from@react-native/typescript-config@0.76.0. RN 0.76 is the oldest version we support, and this list is RN's own statement of the runtime APIs available there."types": []stops the build from loading ambient types, so theliblist is actually enforced.src/globals.d.tsdeclaresconsole.log, the one RN runtime global the SDK uses.The emitted
lib/output is the same as before.Decisions
@react-native/typescript-configis made for apps. It setsnoEmit, bundler module resolution and ESM output. We emit CommonJS.jsand.d.tsfiles, so we would have to override about half of it."types": ["react-native"]. The official config getsconsolefrom the RN types. RN 0.87 (our devDependency) exposes its types only throughpackage.jsonexports, and TypeScript 4.9 withmoduleResolution: "node"cannot resolve them.globals.d.tshas a TODO to remove it after the build moves to TypeScript 5.Out of scope
react-native-builder-bob(see AGENTS.md). Extending the official config makes sense at that point.package.jsondeclares or tests it.🤖 Generated with Claude Code