I'm creating an express route handler and I want to extend the express.Request
interface to document what the params and query properties should be. I would like the jsdoc's to work in had with VsCode intellisense.
At first, I import the Request
and Response
from express.
/**
* @typedef {import('express').Request} Request
* @typedef {import('express').Response} Response
*/
I then create 2 types for the params
and query
.
/**
* @typedef {{
* module: string
* }} params
*/
/**
* @typedef {{
* field: string
* skip: number
* limit: number
* }} query
*/
As a parameter of my function, I extend the express Request
and override my query
and params
.
/**
* @param {Request & {params: params, query: query}} req
* @param {Response} res
*/
async function search(req, res)
Here is where my problem arises... I only get intellisense for the params
, but not for the query
.
Screenshot of req.parmas
intellisense
Screenshot of req.query
intellisense
When I hover my mouse over the req
param I get the following intellisense.
Am I using the 'extend' feature correctly? How can I extend the Request
type & get intellisense for both query
and params
?