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

Incorrect / overly strict types in 21.4.5

Aperta
#4,565 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, node.js, typescript
Ambito
api, backend

Direzione di ricerca

Inizia leggendo le modifiche ai tipi più restrittive referenziate in #4562 e riproduci l’errore TypeScript con l’esempio di request.params validato da Joi. Segui le definizioni dei tipi di request.params e request.query, quindi verifica che il parametro numerico validato segnalato non produca più l’errore da stringa a numero, senza indebolire i controlli dei tipi non correlati.

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

Descrizione

bug
Runtime

Node.js

Runtime version

24.13.1

Module version

21.4.5

Last module version without issue

21.4.4

Used with

No response

Any other relevant information

No response

What are you trying to achieve or the steps to reproduce?

Take advantage of Joi's type handling to directly reference appropriately typed parameters in request.params and request.query. For example:

function greetUser(id: number) {
  assert(typeof id === "number", "ID must be a number");
  return `Hello, user with ID ${id}!`;
}

server.route({
  method: "GET",
  path: "/hello/{id}",
  handler: (request, _h) => {
    // request.params.id is number, not string, because of Joi validation
    return { message: greetUser(request.params.id) };
  },
  options: {
    validate: {
      params: Joi.object({
        id: Joi.number().required(),
      }),
    },
  },
});
What was the result you got?

Starting in Hapi 21.4.5:

Argument of type 'string' is not assignable to parameter of type 'number'.ts(2345)
What result did you expect?

No errors.

I believe that the stricter types in #4562 are too strict. I appreciate stricter typing (even if it breaks compilation in patch releases - #4563) but this seems too strict - from what I understand, relying on Joi to validate queries and route parameters and coerce / convert their types is a core feature of Hapi and is (I assume) a common practice, but the new types act like it isn't permitted / doesn't happen.

Lingua principale
JavaScript
Stelle
14.8k
Fork
1.4k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

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 hapijs/hapi

Tutte le issue di hapijs/hapi

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.