From 8ff23bfaf39b706cbedd509b548ae1aa8192fe2a Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Tue, 22 Sep 2026 11:51:24 -0500 Subject: [PATCH] fix(compiler): declare RequestInfo in fallback ambient - Add the Node-compatible RequestInfo alias without widening supported fetch inputs. - Cover RequestInfo resolution at the shared preflight boundary. Fixes #369 Co-authored-by: Hagege Ruben <20857346+HagegeR@users.noreply.github.com> --- .../ambient/scriptc-node-fallback.d.ts | 3 ++- .../compiler/test/ts7/program-adapter.test.ts | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/compiler/ambient/scriptc-node-fallback.d.ts b/packages/compiler/ambient/scriptc-node-fallback.d.ts index 4a67ad89b..de3efa0ee 100644 --- a/packages/compiler/ambient/scriptc-node-fallback.d.ts +++ b/packages/compiler/ambient/scriptc-node-fallback.d.ts @@ -770,6 +770,7 @@ interface Request { arrayBuffer(): Promise; bytes(): Promise; } +type RequestInfo = string | URL | Request; interface RequestInit { method?: string; headers?: @@ -782,7 +783,7 @@ interface RequestInit { signal?: AbortSignal; } declare var Request: { - new (input: string | URL | Request, init?: RequestInit): Request; + new (input: RequestInfo, init?: RequestInit): Request; readonly prototype: Request; }; declare function fetch(input: string | URL, init?: RequestInit): Promise; diff --git a/packages/compiler/test/ts7/program-adapter.test.ts b/packages/compiler/test/ts7/program-adapter.test.ts index 4b00c66fd..d7540fe19 100644 --- a/packages/compiler/test/ts7/program-adapter.test.ts +++ b/packages/compiler/test/ts7/program-adapter.test.ts @@ -68,6 +68,26 @@ test("retains source-file BOM stripping", () => { } }); +test("fallback ambient resolves RequestInfo during preflight", () => { + const tempRoot = process.platform === "win32" ? tmpdir() : "/tmp"; + const dir = mkdtempSync(join(tempRoot, "scriptc-request-info-")); + const entry = join(dir, "entry.ts"); + writeFileSync(entry, [ + 'const target: RequestInfo = "https://example.invalid/";', + "console.log(typeof target);", + ].join("\n")); + + const load = loadProgram(entry); + try { + const diagnostics = checkPreflight(load); + expect(diagnostics, diagnostics.map((diag) => `${diag.code}: ${diag.message}`).join("\n")) + .toEqual([]); + } finally { + load.dispose(); + rmSync(dir, { recursive: true, force: true }); + } +}); + test("preflight batches symbols in deferred TDZ-analysis roots", () => { const tempRoot = process.platform === "win32" ? tmpdir() : "/tmp"; const dir = mkdtempSync(join(tempRoot, "scriptc-preflight-batch-"));