TS error, "Type 'Query' is not assignable to type 'string'"

Viewed 185

This is more of a general question about using TS with Express. Am I expected to extend the Query interface for every single route on my backend? For instance, if I want to pull out some params,

router.get('/', (req: express.Request, res: express.Response) => {
  const { id } = req.query
  // do something
})

I would get thrown the error that is in the title. I've tried doing something like,

const { id }: { id: string } = req.query

or

const id = req.query!.id

But that doesn't seem to work. What are my options in such a situation?

0 Answers
Related