Skip to content

Conversation

@kantrolv
Copy link

fix(dts): resolve missing type references in lib.deno.ns.d.ts

Overview

This PR resolves multiple type resolution issues in Deno’s TypeScript declaration files, where global and Web API types such as PerformanceMark, WebSocket, and BufferSource were not being detected. These missing type references caused incomplete or incorrect typing within the Deno namespace.

Changes

  • Added missing reference directives to cli/tsc/dts/lib.deno.ns.d.ts:

    • /// <reference path="lib.deno.shared_globals.d.ts" />
    • /// <reference path="lib.deno_websocket.d.ts" />
  • Updated path references in:

    • cli/tsc/dts/lib.deno.shared_globals.d.ts
    • cli/tsc/dts/lib.deno.window.d.ts
      Converted lib references to relative paths to ensure correct type resolution without relying on compiler defaults.

Fixes

#22807

@CLAassistant
Copy link

CLAassistant commented Nov 19, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link

coderabbitai bot commented Nov 19, 2025

Walkthrough

Added a new DenoSystemError interface in Deno.errors with code?: string and updated multiple existing error classes in Deno.errors (e.g., NotFound, PermissionDenied, ConnectionRefused, ConnectionReset, ConnectionAborted, NotConnected, AddrInUse, AddrNotAvailable, BrokenPipe, AlreadyExists, InvalidData, TimedOut, Interrupted, WouldBlock, WriteZero, UnexpectedEof, BadResource, Http, Busy, NotSupported, FilesystemLoop, IsADirectory, NetworkUnreachable, NotADirectory, NotCapable, etc.) to implement DenoSystemError and declare code?: string. Also applied minor formatting adjustments to export statements.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify the DenoSystemError declaration and its placement in Deno.errors.
  • Confirm each updated error class consistently implements DenoSystemError and includes code?: string.
  • Check for syntax/typing issues introduced by the interface implementation.
  • Review the export-statement formatting changes.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly relates to the main objective of fixing type resolution in lib.deno.ns.d.ts, matching the PR's primary goal.
Description check ✅ Passed The description clearly explains the problem, changes made, and references the related issue, directly relating to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3538226 and 67cdc3b.

📒 Files selected for processing (1)
  • cli/tsc/dts/lib.deno.ns.d.ts (16 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test release windows-x86_64
  • GitHub Check: build libs

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
cli/tsc/dts/lib.deno.shared_globals.d.ts (1)

499-499: Constructor spacing normalization is safe and consistent with code style updates.

The new keyword spacing has been standardized across constructor declarations (removing space: new (...)new(...)). This is purely stylistic—both formats are valid TypeScript. Verify this normalization is applied consistently across related .d.ts files mentioned in the PR.

Also applies to: 517-520, 726-726, 780-780, 835-835, 859-859, 883-883

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8bab83 and f401e9f.

📒 Files selected for processing (4)
  • cli/tsc/dts/lib.deno.ns.d.ts (18 hunks)
  • cli/tsc/dts/lib.deno.shared_globals.d.ts (8 hunks)
  • cli/tsc/dts/lib.deno.window.d.ts (5 hunks)
  • cli/tsc/dts/lib.deno_web.d.ts (37 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cli/tsc/dts/lib.deno.shared_globals.d.ts (1)
ext/node/polyfills/worker_threads.ts (1)
  • WorkerOptions (72-92)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: test debug linux-x86_64
  • GitHub Check: test debug linux-aarch64
  • GitHub Check: test release linux-x86_64
  • GitHub Check: test debug windows-x86_64
  • GitHub Check: test debug macos-aarch64
  • GitHub Check: test debug macos-x86_64
  • GitHub Check: build libs
🔇 Additional comments (16)
cli/tsc/dts/lib.deno.window.d.ts (1)

4-8: Triple‑slash path references correctly wire Deno/window/shared globals

Adding explicit /// <reference path="./lib.deno.ns.d.ts" />, ./lib.deno.shared_globals.d.ts, ./lib.deno_webstorage.d.ts, and ./lib.deno_cache.d.ts ensures the window lib sees the Deno namespace and Web Storage/cache types without relying on implicit lib resolution. This directly supports the missing‑types fix; remaining ~ changes in this file are formatting-only (unions and constructor spacing) and do not alter type shapes.

cli/tsc/dts/lib.deno.ns.d.ts (11)

5-11: New lib.deno_ path references align ns lib with Web/URL/Net/WebSocket typings*

The added path references to ./lib.deno_url.d.ts, ./lib.deno_web.d.ts, ./lib.deno_fetch.d.ts, ./lib.deno_net.d.ts, ./lib.deno.shared_globals.d.ts, and ./lib.deno_websocket.d.ts are consistent with the other libs in this folder and should resolve previously missing symbols like PerformanceMark, WebSocket, BufferSource, etc., when consuming the Deno namespace. Cyclic refs with other lib.deno_*.d.ts are acceptable for TS and will be validated by the usual typecheck pipeline.


153-195: DenoSystemError + OS error classes exposing code?: string look correct

Defining export interface DenoSystemError extends Error { code?: string; } and having OS‑level error classes (e.g., NotFound, PermissionDenied, ConnectionRefused, etc.) extends Error implements DenoSystemError { code?: string; } cleanly models the runtime behavior where OS errno codes are surfaced as code. This is backwards‑compatible (property is optional) and significantly improves typings for Node‑style error handling.


280-389: Other Deno.errors changes are type‑only and safe

The rest of the Deno.errors updates here (adding implements DenoSystemError plus optional code on other OS‑backed errors, and leaving purely logical errors like InvalidData, BadResource, Http, NotCapable as plain Error) are consistent and non‑breaking. The closing export { }; is a cosmetic normalization from export {} and doesn’t affect consumers.


3583-3597: FsEvent.kind union reflow is cosmetic

Reformatting FsEvent.kind into a multi‑line string‑literal union ("any" | "access" | "create" | ... | "other") doesn’t change the allowed values and keeps the type precise. No behavioral or compatibility impact.


4204-4222: SysPermissionDescriptor.kind union remains precise after formatting change

The multi‑line union for SysPermissionDescriptor.kind ("loadavg" | "hostname" | ... | "setPriority") preserves the exact same set of string literals; only layout changed. Safe and readable.


4519-4529: Deno.build.os string union formatting change is benign

Reflowing the Deno.build.os union into one per line ("darwin" | "linux" | ... | "illumos") is a style-only change; the OS identifiers remain identical to the previous definition.


5789-5910: FFI helper conditional types: tokens unchanged, just rewrapped

The ToNativeType, ToNativeResultType, ToNativeParameterTypes, FromNativeType, FromNativeResultType, and FromNativeParameterTypes aliases are only reformatted over multiple lines; the nested conditional branches and inferred enum/typed‑pointer cases are otherwise identical. Given their centrality to FFI, it’s good that the change is purely cosmetic.


5965-5999: StaticForeignSymbol and related FFI mapping types are unaffected logically

The StaticForeignSymbol, FromForeignFunction, and StaticForeignLibraryInterface definitions retain the same conditional logic and mapped‑type behavior; only spacing and line breaks changed (including export { }; normalization). No impact on FFI call-site types.


6195-6232: UnsafeCallback changes are purely layout

The UnsafeCallback generic declaration and its threadSafe constructor signature are unchanged aside from line breaks; lifetime and ref/unref semantics are unaffected. Given how sensitive FFI callbacks are, it’s good there’s no behavioral/type change here.


6537-6575: Deno.telemetry namespace export sentinel is style‑only

The added export { }; // only export exports line in Deno.telemetry just normalizes the empty export style and doesn’t alter the exposed API (tracerProvider, contextManager, meterProvider). Safe to merge.


6577-6578: Final export { }; sentinel is harmless

The terminal export { }; // only export exports inside the Deno namespace is equivalent to the prior export {} usage and simply preserves module semantics for tooling. No behavioral impact.

cli/tsc/dts/lib.deno_web.d.ts (2)

7-7: New reference to lib.deno.window.d.ts completes Web/window type wiring

Adding /// <reference path="./lib.deno.window.d.ts" /> here ensures the web lib has direct access to the window/navigator/location (and related event/stream) declarations defined in lib.deno.window.d.ts, which in turn now references the ns/shared globals libs. This matches the PR’s goal of fixing missing global/Web API typings in the Deno namespace.


42-1696: Constructor/union formatting tweaks across web lib are cosmetic

All the ~ changes across this file (constructor signatures like new(): X or new(label?: string, ...), union types reflowed over multiple lines, and controller/stream new(): never declarations) preserve the same parameter lists, return types, and literal unions as before. There are no observable type‑shape or API surface changes—just normalization of spacing.

cli/tsc/dts/lib.deno.shared_globals.d.ts (2)

1-1: Flag: AI-generated summary describes types not present in this file.

The summary mentions DenoSystemError interface and OS-level error classes implementing it, but these do not appear in the provided file. This inconsistency suggests the summary may conflate changes from multiple files. Cross-reference the PR description with actual file changes to ensure alignment.


8-16: All referenced declaration files exist and paths resolve correctly.

The reference directive conversion from implicit lib= to explicit path= references is valid. All 9 .d.ts files are present in the cli/tsc/dts directory and paths resolve as expected. The constructor formatting changes (removing spaces after new keyword) are consistent stylistic improvements with no functional impact.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
repro_issue.ts (1)

5-9: Update repro comments and remove obsolete @ts-ignore

Given Deno.errors.NotFound now has code?: string in the typings, the @ts-ignore on Line 5 and the comment on Line 8 ("should fail type checking currently") are outdated. The line should type-check successfully after your changes.

Recommend:

  • Drop the @ts-ignore on Line 5.
  • Rephrase the Line 8 comment to something like: “This line used to fail type checking before the fix; it should now compile and see code as an optional string.”
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f401e9f and b9339c2.

📒 Files selected for processing (12)
  • check_ns.ts (1 hunks)
  • check_tsconfig.json (1 hunks)
  • cli/tsc/dts/lib.deno.ns.d.ts (8 hunks)
  • cli/tsc/dts/lib.deno.shared_globals.d.ts (1 hunks)
  • cli/tsc/dts/lib.deno.window.d.ts (1 hunks)
  • cli/tsc/dts/lib.deno_web.d.ts (1 hunks)
  • repro_issue.ts (1 hunks)
  • tests/unit/error_test.ts (1 hunks)
  • tests/unit/read_file_test.ts (3 hunks)
  • verify_fix.js (1 hunks)
  • verify_fix.ts (1 hunks)
  • verify_tsconfig.json (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
verify_fix.ts (1)
verify_fix.js (2)
  • c (4-4)
  • cs (5-5)
repro_issue.ts (1)
cli/tsc/dts/lib.deno.ns.d.ts (1)
  • NotFound (192-194)
🔇 Additional comments (7)
cli/tsc/dts/lib.deno.window.d.ts (1)

4-8: Reference structure looks correct.

The path-based references establish proper dependencies on the Deno namespace and shared globals before loading specialized APIs (webstorage, cache). The ordering is appropriate.

cli/tsc/dts/lib.deno_web.d.ts (1)

7-7: Appropriate reference addition.

Adding the window type reference here allows web API types to properly resolve Window-related interfaces. This aligns with the PR's goal of fixing missing Web API type detection.

cli/tsc/dts/lib.deno.shared_globals.d.ts (1)

8-16: All referenced files exist and are properly structured.

Verification confirms all 10 referenced .d.ts files exist in the same directory. The circular reference between lib.deno.shared_globals.d.ts and lib.deno.ns.d.ts (at lines 16 and 9 respectively) is a standard, safe pattern in TypeScript declaration files and poses no issues for type resolution. The conversion from ambient to explicit path-based references should resolve the intended type resolution issues.

cli/tsc/dts/lib.deno.ns.d.ts (2)

152-163: LGTM! Well-designed interface for OS-level errors.

The DenoSystemError interface with optional code property cleanly separates OS-level errors (which may include system error codes like "ENOENT") from Deno-specific errors. The documentation is clear and the design allows backward compatibility.


192-375: Correct implementation of DenoSystemError across error classes.

The error classes are properly categorized:

  • OS-level errors (NotFound, PermissionDenied, ConnectionRefused, etc.) correctly implement DenoSystemError with optional code?: string
  • Deno-specific errors (InvalidData, BadResource, NotCapable, etc.) correctly remain as plain Error without the code property

This matches the intended behavior described in the tests.

tests/unit/read_file_test.ts (1)

167-171: Good type-safe approach to accessing the optional code property.

Using type guards before accessing the code property is the correct pattern. This ensures type safety and handles cases where the error might be of an unexpected type. The changes properly align with the new DenoSystemError interface.

Also applies to: 182-186

tests/unit/error_test.ts (1)

36-68: Comprehensive test coverage for the DenoSystemError interface.

The test properly validates:

  • OS-level errors (NotFound, PermissionDenied, ConnectionRefused) have the optional code property
  • Deno-specific errors (InvalidData, BadResource, NotCapable) do not have the code property
  • The @ts-expect-error comments provide compile-time validation

This ensures the type system correctly reflects the intended design.

Comment on lines 1 to 13
{
"compilerOptions": {
"target": "esnext",
"lib": [
"esnext"
],
"types": [],
"skipLibCheck": true
},
"files": [
"./verify_fix.ts"
]
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Missing "dom" lib in configuration.

The verify_fix.ts file uses Cache and CacheStorage, which are DOM types, but this config doesn't include "dom" in the lib array. While the triple-slash reference in verify_fix.ts might work, this creates an inconsistency with check_tsconfig.json which explicitly includes the "dom" lib.

Also note the different skipLibCheck value (true here vs false in check_tsconfig.json) - if both are verification/test configs, consider making them consistent.

Apply this diff:

 {
   "compilerOptions": {
     "target": "esnext",
     "lib": [
-      "esnext"
+      "esnext",
+      "dom"
     ],
     "types": [],
-    "skipLibCheck": true
+    "skipLibCheck": false
   },
   "files": [
     "./verify_fix.ts"
   ]
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{
"compilerOptions": {
"target": "esnext",
"lib": [
"esnext"
],
"types": [],
"skipLibCheck": true
},
"files": [
"./verify_fix.ts"
]
}
{
"compilerOptions": {
"target": "esnext",
"lib": [
"esnext",
"dom"
],
"types": [],
"skipLibCheck": false
},
"files": [
"./verify_fix.ts"
]
}
🤖 Prompt for AI Agents
In verify_tsconfig.json around lines 1 to 13, the config omits the "dom" lib and
has skipLibCheck: true causing inconsistency with check_tsconfig.json; update
the "lib" array to include "dom" (e.g. ["esnext","dom"]) and set "skipLibCheck"
to the same value as check_tsconfig.json (change to false) so DOM types like
Cache and CacheStorage resolve consistently.

@kantrolv kantrolv force-pushed the missingtypes branch 2 times, most recently from bf474c4 to f699ff6 Compare November 20, 2025 10:55
Copy link
Member

Choose a reason for hiding this comment

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

Why are tests in this file changed?

Copy link
Author

Choose a reason for hiding this comment

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

Why are tests in this file changed?

I've reverted the read_file_test.ts changes. The PR now only contains type definitions in lib.deno.ns.d.ts and type-level tests in error_test.ts. Thanks for the feedback! Let me know if there is anything I can do.

Added code?: string property to all error classes implementing DenoSystemError.
This allows TypeScript to accept accessing the code property on error instances
without type errors.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1aa8d8 and 3538226.

📒 Files selected for processing (1)
  • cli/tsc/dts/lib.deno.ns.d.ts (17 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: test debug linux-x86_64
  • GitHub Check: build libs
🔇 Additional comments (1)
cli/tsc/dts/lib.deno.ns.d.ts (1)

5-10: LGTM - Reference directives updated correctly.

The reference directives now use relative paths (./), which aligns with the PR objectives to ensure correct type resolution. Lines 9-10 specifically add the references mentioned in the PR description.

Comment on lines 5 to 10
/// <reference path="./lib.deno_net.d.ts" />
/// <reference path="./lib.deno_url.d.ts" />
/// <reference path="./lib.deno_web.d.ts" />
/// <reference path="./lib.deno_fetch.d.ts" />
/// <reference path="./lib.deno_websocket.d.ts" />
/// <reference path="./lib.deno.shared_globals.d.ts" />
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Critical inconsistency between PR description and actual changes.

The PR objectives state this change adds reference directives to resolve missing types (lines 5-10 show these reference additions). However, the bulk of this diff (lines 174-342) introduces a completely unrelated DenoSystemError interface and modifies 21+ error classes to implement it.

This suggests either:

  1. The wrong diff was uploaded for review
  2. The PR description is incorrect
  3. Multiple unrelated changes were accidentally committed together

Lines 5-10 match the PR description, but lines 174-342 are a major error system refactoring that has nothing to do with "resolving missing types in lib.deno.ns.d.ts via reference directives."

Please clarify: Is this the correct diff for PR #31349, or have unrelated changes been mixed in?

Also applies to: 174-342

🤖 Prompt for AI Agents
In cli/tsc/dts/lib.deno.ns.d.ts around lines 5-10 and 174-342, the PR adds
reference directives at lines 5-10 (matching the description) but also
introduces an unrelated DenoSystemError interface and modifies many error
classes at lines 174-342; this is a mixed-change issue — either remove the
unrelated error-system refactor from this PR or split it into a separate PR and
update the commit/branch accordingly. Revert the DenoSystemError/interface and
error-class changes from this branch (or move those commits to a new branch/PR),
keep only the reference directive changes here, and update the PR
title/description to accurately reflect the contained change; if you intend to
keep both, split into two logical commits with clear descriptions and update the
review to reference both PRs.

Added code?: string property to all error classes implementing DenoSystemError.
This allows TypeScript to accept accessing the code property on error instances.
@kantrolv kantrolv closed this by deleting the head repository Nov 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants