Skip to content

fix(types): align FetchError.errno with NodeJS ErrnoException#1875

Open
nthbotast wants to merge 1 commit into
node-fetch:mainfrom
nthbotast:fix-fetcherror-errno-type-1831
Open

fix(types): align FetchError.errno with NodeJS ErrnoException#1875
nthbotast wants to merge 1 commit into
node-fetch:mainfrom
nthbotast:fix-fetcherror-errno-type-1831

Conversation

@nthbotast
Copy link
Copy Markdown

@nthbotast nthbotast commented Mar 6, 2026

Summary

  • update FetchError.errno type from string to NodeJS.ErrnoException['errno']
  • keep type behavior aligned with Node's ErrnoException contract
  • adjust the existing type test snippet to accept both number and string errno values

Closes #1831

Validation

  • git diff --cached --check
  • ⚠️ npm run test-types currently fails in this ephemeral environment due to @types/node/http2.d.ts parser/type errors (toolchain mismatch), unrelated to this patch

Copy link
Copy Markdown

@rsbasic rsbasic left a comment

Choose a reason for hiding this comment

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

Review: APPROVE (types only, LOW risk)

Changes FetchError.errno type from string to NodeJS.ErrnoException['errno']. This is a type-level correction — no runtime code changes.

The current type (errno?: string) is inaccurate. Node.js ErrnoException.errno is number | undefined, not string. The existing type lets TypeScript users write code like if (err.errno === 'ECONNREFUSED') which compiles but is incorrect at runtime — errno is a numeric system error code, not a string error name. That is what err.code is for.

The test file change (throw new TypeError(error.errno as string | undefined)throw new TypeError(String(error.errno))) is consistent — it no longer assumes errno is a string.

One consideration: This is technically a breaking change for TypeScript consumers who currently compare errno to string values. Those comparisons are already wrong at runtime (they would never match), so fixing the type surfaces existing bugs rather than introducing new ones.

Verdict: Safe to merge. Corrects a type inaccuracy that masks real bugs.

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.

Why is FetchError.errno a string and not a number?

2 participants