From c93b49a1130ef25c6a27c32d2fb6f866d06b138d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliv=C3=A9r=20Falvai?= Date: Tue, 22 Sep 2026 16:58:59 +0200 Subject: [PATCH] Align SDK tsconfig lib with React Native 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) --- src/globals.d.ts | 8 ++++++++ tsconfig.build.json | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/globals.d.ts diff --git a/src/globals.d.ts b/src/globals.d.ts new file mode 100644 index 00000000..04575759 --- /dev/null +++ b/src/globals.d.ts @@ -0,0 +1,8 @@ +// Globals the RN runtime provides that are not in the ES lib, declared narrowly instead of pulling in lib "dom" or @types/node. +// Interface + var (not const) so this merges with those declarations when an editor or other config also loads them. +// TODO: replace this file with `"types": ["react-native"]` (as @react-native/typescript-config does) once the build +// moves to TypeScript 5 and `moduleResolution: "bundler"`: RN exposes its types only through package.json "exports". +interface Console { + log(...data: any[]): void; +} +declare var console: Console; diff --git a/tsconfig.build.json b/tsconfig.build.json index c5458d14..e1263270 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -9,7 +9,12 @@ "compilerOptions": { "target": "ES5", "module": "commonjs", - "lib": ["es6"], + // A subset of what RN supports at the oldest supported version (0.76). Widen it only as far as RN's list: + // https://github.com/facebook/react-native/blob/0.76-stable/packages/typescript-config/tsconfig.json + "lib": ["es2019"], + // No ambient @types/* (e.g. Node), otherwise they add their own libs and the list above is not enforced. + // RN globals come from src/globals.d.ts instead. + "types": [], "declaration": true, "noImplicitAny": true, "noEmitOnError": true,