Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

873
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!