Skip to content

Replace /// <reference types="node" /> with explicit import type in typings#447

Merged
grs merged 1 commit intoamqp:mainfrom
deyaaeldeen:fix/remove-reference-directives
Apr 14, 2026
Merged

Replace /// <reference types="node" /> with explicit import type in typings#447
grs merged 1 commit intoamqp:mainfrom
deyaaeldeen:fix/remove-reference-directives

Conversation

@deyaaeldeen
Copy link
Copy Markdown
Contributor

Remove the triple-slash directive /// <reference types="node" /> from all 16 typing files in typings/. This directive injects the entire @types/node global namespace into any TypeScript project that imports rhea, even when compiling for non-Node targets (React Native, browser, Cloudflare Workers), causing type conflicts.

What changed

  • Removed /// <reference types="node" /> from all 16 .d.ts files
  • Added import type { Buffer } from "buffer" to the 9 files that use Buffer without an explicit import (connection.d.ts, frames.d.ts, link.d.ts, message.d.ts, sasl.d.ts, session.d.ts, transport.d.ts, types.d.ts, util.d.ts)
  • Files that already had explicit import { ... } from "events" / import { ... } from "net" needed no additional changes

Why

The /// <reference types="node" /> is a legacy pattern from before import type existed. It pulls in all Node.js type definitions globally, which conflicts with other platform type definitions (e.g., react-native, lib.dom.d.ts) that define the same globals (FormData, AbortController, Blob, etc.).

Using explicit import type resolves identically for Node consumers (since @types/node provides the "buffer", "events", and "net" modules) but avoids polluting consumers' global type namespace.

Validation

  • tsc --noEmit passes with zero errors
  • Non-breaking change: all types resolve identically for Node consumers

Fixes #446

…ypings

Remove the triple-slash directive `/// <reference types="node" />` from all
16 typing files. This directive injects the entire @types/node global namespace
into any TypeScript project that imports rhea, even when compiling for non-Node
targets (React Native, browser, Cloudflare Workers), causing type conflicts.

Many files already use explicit imports from "events" and "net". For files
that use Buffer without an explicit import, add `import type { Buffer } from
"buffer"` — this resolves identically for Node consumers but avoids polluting
the global type namespace.

Fixes amqp#446
@grs grs merged commit 1a69756 into amqp:main Apr 14, 2026
5 checks passed
@deyaaeldeen deyaaeldeen deleted the fix/remove-reference-directives branch April 14, 2026 13:47
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.

Replace /// <reference types="node" /> with explicit import type in typings

2 participants