Skip to content

typings: fix internal type resolution - #66512

Merged
Renegade334 merged 2 commits into
nodejs:mainfrom
leah-1ee:typings/fix-internal-type-resolution
Nov 2, 2026
Merged

Renegade334 merged 2 commits into
nodejs:mainfrom
leah-1ee:typings/fix-internal-type-resolution

Conversation

@leah-1ee

@leah-1ee leah-1ee commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

With TypeScript 5.9.3, the root project reports 51 TS2451 diagnostics because builtin files such as primordials.js and realm.js are treated as scripts. Their wrapper-local declarations consequently collide with standard library globals. The ICU declaration also reports TS2580 because its Buffer return type has no local type definition.

Set moduleDetection: "force" to separate file scopes. This alone would remove the shared internalBinding type information, so add an ambient let that reuses the existing generic function type and binding map. This preserves binding inference without exposing a globalThis.internalBinding property.

Define the ICU Buffer alias as Uint8Array, following the existing byte-view convention in internal binding declarations. No runtime code is changed.

Validation:

  • The root project passes with TypeScript 5.9.3 and --noEmit --skipLibCheck false, removing all 52 diagnostics.
  • All 567 input files and the return types of 420 existing internalBinding references are preserved.

Refs: #49742
Refs: #59176

Assisted-by: Codex

@nodejs-github-bot nodejs-github-bot added the typings Issues and PRs related to internal TypeScript declarations. label Oct 4, 2026
Comment thread typings/internalBinding/icu.d.ts Outdated
@@ -1,3 +1,5 @@
type Buffer = Uint8Array;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
type Buffer = Uint8Array;
import { FastBuffer as Buffer } from 'internal/buffer';

Comment thread tsconfig.json Outdated
"target": "ESNext",
"module": "CommonJS",
"moduleDetection": "force",
"baseUrl": ".",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
"baseUrl": ".",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review and suggestions! I've applied all three suggestions. I also updated the JSDoc reference in realm.js and converted five type imports in resolve.js and package_json_reader.js to relative paths to preserve their type information.

Comment thread typings/globals.d.ts Outdated
Comment on lines +111 to +115
declare function internalBinding<T extends InternalBindingKeys>(binding: T): InternalBindingMap[T]

declare global {
// Supplied to internal modules by the builtin function wrapper.
let internalBinding: typeof import('./globals').internalBinding;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just move the function definition, there's no need to juggle this now that the global scope clash with internal/bootstrap/realm is removed by the moduleDetection setting.

Suggested change
declare function internalBinding<T extends InternalBindingKeys>(binding: T): InternalBindingMap[T]
declare global {
// Supplied to internal modules by the builtin function wrapper.
let internalBinding: typeof import('./globals').internalBinding;
declare global {
// Supplied to internal modules by the builtin function wrapper.
function internalBinding<T extends InternalBindingKeys>(binding: T): InternalBindingMap[T]

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 <selee3196@gmail.com>
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 <selee3196@gmail.com>
@leah-1ee
leah-1ee force-pushed the typings/fix-internal-type-resolution branch from dcbaadc to 4a82eb2 Compare October 5, 2026 14:55
@codecov

codecov Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.39%. Comparing base (bbd566d) to head (4a82eb2).
⚠️ Report is 422 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66512      +/-   ##
==========================================
- Coverage   92.74%   90.39%   -2.35%     
==========================================
  Files         422      791     +369     
  Lines      193170   275991   +82821     
  Branches    29783    52971   +23188     
==========================================
+ Hits       179160   249494   +70334     
- Misses      13682    16903    +3221     
- Partials      328     9594    +9266     
Files with missing lines Coverage Δ
lib/internal/bootstrap/realm.js 97.09% <100.00%> (+0.77%) ⬆️
lib/internal/modules/esm/resolve.js 99.02% <100.00%> (+12.52%) ⬆️
lib/internal/modules/package_json_reader.js 99.28% <100.00%> (+12.38%) ⬆️

... and 496 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@leah-1ee

Copy link
Copy Markdown
Contributor Author

@Renegade334 Hi, thanks again for your review! I've addressed your suggestions in the latest commit.

Would you mind taking another look when you have a chance? Thanks!

@Renegade334 Renegade334 added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 2, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. and removed commit-queue PRs queued for automated landing through the Commit Queue. labels Nov 2, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Commit Queue failed

   ⚠  Could not retrieve the email or name of the PR's author from user's GitHub profile!
   ✖  No Jenkins CI runs detected

The pull request was removed from the Commit Queue and labeled commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. . After resolving the failure, remove that label and add commit-queue PRs queued for automated landing through the Commit Queue. to retry.

Full Commit Queue output
�[36m⠋�[39m Loading data for nodejs/node/pull/66512
�[36m⠋�[39m Loading data for nodejs/node/pull/66512
�[36m⠋�[39m Getting collaborator contacts from README of nodejs/node
�[36m⠋�[39m Getting PR from nodejs/node/pull/66512
�[36m⠋�[39m Getting reviews from nodejs/node/pull/66512
�[36m⠋�[39m Getting comments from nodejs/node/pull/66512
�[36m⠋�[39m Getting commits from nodejs/node/pull/66512
✔  Done loading data for nodejs/node/pull/66512
----------------------------------- PR info ------------------------------------
Title      typings: fix internal type resolution (#66512)
   ⚠  Could not retrieve the email or name of the PR's author from user's GitHub profile!
Branch     leah-1ee:typings/fix-internal-type-resolution -> nodejs:main
Labels     commit-queue, typings
Commits    2
 - typings: fix internal type resolution
 - typings: address type resolution review feedback
Committers 1
 - leah-1ee <selee3196@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/66512
Refs: https://github.com/nodejs/node/pull/49742
Refs: https://github.com/nodejs/node/pull/59176
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/66512
Refs: https://github.com/nodejs/node/pull/49742
Refs: https://github.com/nodejs/node/pull/59176
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Sun, 04 Oct 2026 16:22:14 GMT
   ✔  Approvals: 1
   ✔  - René (@Renegade334): https://github.com/nodejs/node/pull/66512#pullrequestreview-5743393744
   ✔  Last GitHub CI successful
   ✖  No Jenkins CI runs detected
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu

View workflow run

@Renegade334
Renegade334 merged commit 6673264 into nodejs:main Nov 2, 2026
38 checks passed
@Renegade334

Copy link
Copy Markdown
Member

Landed in 6673264

aduh95 pushed a commit that referenced this pull request Nov 11, 2026
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 <selee3196@gmail.com>
PR-URL: #66512
Refs: #49742
Refs: #59176
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit-queue-failed PRs whose Commit Queue landing failed and need manual intervention before retrying. typings Issues and PRs related to internal TypeScript declarations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants