From 4bac5e5da88a7324d8fa839ac1219bcb5a77336c Mon Sep 17 00:00:00 2001 From: leah-1ee Date: Mon, 5 Oct 2026 01:16:16 +0900 Subject: [PATCH 1/2] typings: fix internal type resolution Treat builtin JavaScript files as modules to avoid script-scope collisions with standard library declarations. Explicitly provide the existing internalBinding type so binding inference is preserved. Define the ICU Buffer alias using the existing Uint8Array convention. Assisted-by: Codex Signed-off-by: leah-1ee --- tsconfig.json | 1 + typings/globals.d.ts | 3 +++ typings/internalBinding/icu.d.ts | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tsconfig.json b/tsconfig.json index d08908af141a..922f026b51e1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,6 +12,7 @@ "lib": ["ESNext", "DOM"], "target": "ESNext", "module": "CommonJS", + "moduleDetection": "force", "baseUrl": ".", "paths": { "_http_agent": ["./lib/_http_agent.js"], diff --git a/typings/globals.d.ts b/typings/globals.d.ts index 7b6cb962c82d..30c038cd4dd9 100644 --- a/typings/globals.d.ts +++ b/typings/globals.d.ts @@ -111,6 +111,9 @@ type InternalBindingKeys = keyof InternalBindingMap; declare function internalBinding(binding: T): InternalBindingMap[T] declare global { + // Supplied to internal modules by the builtin function wrapper. + let internalBinding: typeof import('./globals').internalBinding; + type TypedArray = | Uint8Array | Uint8ClampedArray diff --git a/typings/internalBinding/icu.d.ts b/typings/internalBinding/icu.d.ts index 7a688a5f0823..11b61e58796e 100644 --- a/typings/internalBinding/icu.d.ts +++ b/typings/internalBinding/icu.d.ts @@ -1,3 +1,5 @@ +type Buffer = Uint8Array; + export interface ICUBinding { Converter: object; decode( From 4a82eb23269e0bdf7888fc9c95511c11daf0ca3c Mon Sep 17 00:00:00 2001 From: leah-1ee Date: Mon, 5 Oct 2026 12:40:47 +0900 Subject: [PATCH 2/2] typings: address type resolution review feedback Use FastBuffer for ICU and move internalBinding into declare global. Remove baseUrl and update JSDoc references to preserve type links. Assisted-by: Codex Signed-off-by: leah-1ee --- lib/internal/bootstrap/realm.js | 2 +- lib/internal/modules/esm/resolve.js | 2 +- lib/internal/modules/package_json_reader.js | 8 ++++---- tsconfig.json | 1 - typings/globals.d.ts | 4 +--- typings/internalBinding/icu.d.ts | 2 +- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/internal/bootstrap/realm.js b/lib/internal/bootstrap/realm.js index 3e3473b000c5..fd3e4eb64c80 100644 --- a/lib/internal/bootstrap/realm.js +++ b/lib/internal/bootstrap/realm.js @@ -160,7 +160,7 @@ const legacyWrapperList = new SafeSet([ /** * Set up internalBinding() in the closure. - * @type {import('typings/globals').internalBinding} + * @type {typeof globalThis.internalBinding} */ let internalBinding; { diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 0d00f014147d..ac057127a717 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -158,7 +158,7 @@ function emitLegacyIndexDeprecation(url, path, pkgPath, base, main) { * 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node) * 5. NOT_FOUND * @param {URL} packageJSONUrl - * @param {import('typings/internalBinding/modules').PackageConfig} packageConfig + * @param {import('../../../../typings/internalBinding/modules').PackageConfig} packageConfig * @param {string | URL | undefined} base * @returns {URL} */ diff --git a/lib/internal/modules/package_json_reader.js b/lib/internal/modules/package_json_reader.js index ea6b7d26395e..ef9d118b20ce 100644 --- a/lib/internal/modules/package_json_reader.js +++ b/lib/internal/modules/package_json_reader.js @@ -35,9 +35,9 @@ const { /** - * @typedef {import('typings/internalBinding/modules').DeserializedPackageConfig} DeserializedPackageConfig - * @typedef {import('typings/internalBinding/modules').PackageConfig} PackageConfig - * @typedef {import('typings/internalBinding/modules').SerializedPackageConfig} SerializedPackageConfig + * @typedef {import('../../../typings/internalBinding/modules').DeserializedPackageConfig} DeserializedPackageConfig + * @typedef {import('../../../typings/internalBinding/modules').PackageConfig} PackageConfig + * @typedef {import('../../../typings/internalBinding/modules').SerializedPackageConfig} SerializedPackageConfig */ /** @@ -220,7 +220,7 @@ function getNearestParentPackageJSON(checkPath) { /** * Returns the package configuration for the given resolved URL. * @param {URL | string} resolved - The resolved URL. - * @returns {import('typings/internalBinding/modules').PackageConfig} - The package configuration. + * @returns {import('../../../typings/internalBinding/modules').PackageConfig} - The package configuration. */ function getPackageScopeConfig(resolved) { const result = loaderMethods.getPackageScopeConfig(`${resolved}`); diff --git a/tsconfig.json b/tsconfig.json index 922f026b51e1..b5843469a0f0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,6 @@ "target": "ESNext", "module": "CommonJS", "moduleDetection": "force", - "baseUrl": ".", "paths": { "_http_agent": ["./lib/_http_agent.js"], "_http_client": ["./lib/_http_client.js"], diff --git a/typings/globals.d.ts b/typings/globals.d.ts index 30c038cd4dd9..4a7c52ab7744 100644 --- a/typings/globals.d.ts +++ b/typings/globals.d.ts @@ -108,11 +108,9 @@ interface InternalBindingMap { type InternalBindingKeys = keyof InternalBindingMap; -declare function internalBinding(binding: T): InternalBindingMap[T] - declare global { // Supplied to internal modules by the builtin function wrapper. - let internalBinding: typeof import('./globals').internalBinding; + function internalBinding(binding: T): InternalBindingMap[T] type TypedArray = | Uint8Array diff --git a/typings/internalBinding/icu.d.ts b/typings/internalBinding/icu.d.ts index 11b61e58796e..4c0a364b87d9 100644 --- a/typings/internalBinding/icu.d.ts +++ b/typings/internalBinding/icu.d.ts @@ -1,4 +1,4 @@ -type Buffer = Uint8Array; +import { FastBuffer as Buffer } from 'internal/buffer'; export interface ICUBinding { Converter: object;