Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

874
Vistas
Why are Next.js' req.query object's values of type string | string[]?

Next.js' API Routes receive a req object - it's an extension of http.IncomingMessage with additional middlewares such as req.query. The typing of req.query, found in their utils.ts, is:

query: {
    [key: string]: string | string[]
}

Why is it possible to receive an array of strings from the query?

I'm trying to perform string methods on my query values but run into TS errors -_-

someString.split() // => Property 'split' does not exist on type 'string | string[]'.
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

I think we can use this, if we don't work with more than one param with the same name:

const id = req.query.id as string
over 4 years ago · Santiago Trujillo Denunciar

0

You can convert 'string | string[]' to 'string' by joining them like this:

let { param } = req.query.param;
if (Array.isArray(param)) {
  param = param.join('');
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda