Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

DispatchOptions.upgrade accepts boolean in types but runtime rejects it

Aperta Adatta ai principianti
#5,466 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@mcollina ci sta già lavorando.

Dal 2/7/2026.

  • #5485 di @mcollina — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
javascript, typescript
Ambito
api, backend

Direzione di ricerca

Inizia da types/dispatcher.d.ts:116-117 e lib/core/request.js:134-136, quindi segui il percorso di errore in lib/dispatcher/dispatcher-base.js:172-180. Verifica le convenzioni esistenti per i test di tipo e di runtime relativi a DispatchOptions e alla validazione delle request. Il lavoro è completato quando il contratto pubblico di upgrade corrisponde al comportamento a runtime, gli upgrade string validi continuano a essere accettati e i valori non validi sono coperti tramite il percorso di errore dell’handler.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

DispatchOptions.upgrade currently accepts boolean in the public TypeScript type, but the runtime request validator rejects any truthy non-string value with InvalidArgumentError: upgrade must be a string. A TypeScript-valid call such as client.dispatch({ path: '/', method: 'GET', upgrade: true }, handler) therefore fails before any connector/network dispatch.

Code path

Producer / validator / feedback anchors:

  • types/dispatcher.d.ts:116-117: upgrade?: boolean | string | null;
  • lib/core/request.js:134-136: truthy upgrade values are rejected unless typeof upgrade === 'string'.
  • lib/dispatcher/dispatcher-base.js:172-180: the validator failure is surfaced through handler.onResponseError(null, err) and dispatch() returns false when the handler has an error hook.

Steps to reproduce

Validation level: dynamic reproduction plus source-control-flow validation.

const { Client } = require('undici')

const client = new Client('http://127.0.0.1:9', {
  connect () {
    throw new Error('connector should not be reached when option validation fails')
  },
})

const handler = {
  onRequestStart () {},
  onResponseStart () {},
  onResponseData () {},
  onResponseEnd () {},
  onResponseError (_controller, err) {
    console.log(`handler.error.name=${err.name}`)
    console.log(`handler.error.message=${err.message}`)
  },
}

console.log(client.dispatch({ path: '/', method: 'GET', upgrade: true }, handler))

Observed output from the local repro:

handler.error.name=InvalidArgumentError
handler.error.message=upgrade must be a string
dispatch_return=false

Expected behavior

The public type and runtime validator should agree on the upgrade option contract. Either boolean should be rejected by TypeScript, or true should be normalized to a well-defined upgrade token.

Actual behavior

The TypeScript surface permits upgrade: true, but runtime rejects it before dispatch and reports upgrade must be a string.

Existing coverage

I searched current open/closed issues and PRs for upgrade must be a string, DispatchOptions upgrade boolean, and related types/dispatcher.d.ts upgrade terms. I did not find exact coverage. Nearby upgrade/WebSocket issues and PRs appear to cover protocol behavior, not this type/runtime option drift.

Suggested fix

The lower-risk fix is to narrow DispatchOptions.upgrade to string | null, matching the current runtime validator. If boolean support is intended, the runtime should define and test what true means.

Suggested tests

  • Add a type-level negative assertion for upgrade: true on DispatchOptions if narrowing the type.
  • Keep or add a runtime test that upgrade: 'websocket' remains accepted.
  • Keep invalid non-string runtime values flowing to onResponseError.

Submitted with Codex.

Lingua principale
JavaScript
Stelle
7.7k
Fork
931
Merge medio
3g 1h
PR unite (30g)
92

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di nodejs/undici

Tutte le issue di nodejs/undici

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.