Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Broken typings when upgrading to 21.4.0

Abierto
#4,547 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
node.js, typescript
Área
api, backend

Línea de trabajo

Comienza reproduciendo el ejemplo de TypeScript con node.js 22.15.1 y compara las definiciones de tipos de Request y RouteOptions entre las versiones 21.3.12 y 21.4.0. Rastrea la incompatibilidad relacionada con route.settings.pre y los tipos de payload genéricos. Se considera terminado cuando una someFunction compartida puede aceptar requests de handlers con distintos payloads sin el error TS2345 indicado.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug
Runtime

node.js

Runtime version

22.15.1

Module version

21.4.0

Last module version without issue

21.3.12

Used with

No response

Any other relevant information

No response

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

We have handle who look simplified like this:

export const create = ():RouteOptions => ({
  handler: async (req: Request<{ Payload: { from: string; to: string; } }>, h: ResponseToolkit): Promise<ResponseObject> => {
    const from = req.payload.from
    const to = req.payload.to
    .....
    await someFunction(req);

    return h.response().code(201);
  },
});

export const someFunction = async (request: Request): Promise<void> => ({
   .....
})
What was the result you got?

I get a typescript error:

error TS2345: Argument of type 'Request<{ Payload: { from: string; to: string; }; }>' is not assignable to parameter of type 'Request<ReqRefDefaults>'.
  The types of 'route.settings.pre' are incompatible between these types.
    Type 'RouteOptionsPreArray<{ Payload: { from: string; to: string; }; }> | undefined' is not assignable to type 'RouteOptionsPreArray<ReqRefDefaults> | undefined'.
      Type 'RouteOptionsPreArray<{ Payload: { from: string; to: string; }; }>' is not assignable to type 'RouteOptionsPreAllOptions<ReqRefDefaults>[]'.
        Type 'RouteOptionsPreAllOptions<{ Payload: { from: string; to: string; }; }>' is not assignable to type 'RouteOptionsPreAllOptions<ReqRefDefaults>'.
          Type 'Method<{ Payload: { from: string; to: string; }; }, ReturnValue<{ Payload: { from: string; to: string; }; }>>' is not assignable to type 'RouteOptionsPreAllOptions<ReqRefDefaults>'.
            Type 'Method<{ Payload: { from: string; to: string; }; }, ReturnValue<{ Payload: { from: string; to: string; }; }>>' is not assignable to type 'Method<ReqRefDefaults, ReturnValue<ReqRefDefaults>>'.
              Types of parameters 'request' and 'request' are incompatible.
                Type 'Request<ReqRefDefaults>' is not assignable to type 'Request<{ Payload: { from: string; to: string; }; }>'.
                  Types of property 'payload' are incompatible.
                    Type 'string | object | Readable | Buffer<ArrayBufferLike>' is not assignable to type '{ from: string; to: string; }'.
                      Type 'string' is not assignable to type '{ from: string; to: string; }'.

To fix this problem I need to change:

export const someFunction = async (request: Request<{ Payload: { from: string; to: string; } }>): Promise<void> => ({
   .....
})

but this does not work out if someFunction is used by different handler with different payloads.

What result did you expect?

keep it the way as in 21.3.12 an not have an error here.

Lenguaje dominante
JavaScript
Estrellas
14.8k
Forks
1.4k
Merge medio
17 min
PR fusionados (30 d)
4

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de hapijs/hapi

Todos los issues de hapijs/hapi

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.