-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
I'm trying to add types from 'express' module in nodejs code. I'm not using any compilers. Below are 3 different ways that I've tried with various levels of success. Is there a right way to do it?
TypeScript Version: VSCode 1.19.3
Search Terms:
Salsa, JSDoc, Express
Code
- Require doesn't work as expected:
var express = require('express')
/**
*
* @param {express.Request} req
* @param {express.Response} res
*/
function routeHandler(req, res) {
// req: any
// res: any
}
- Import is working as expected but not supported by nodejs natively:
import express from "express";
/**
*
* @param {express.Request} req
* @param {express.Response} res
*/
function routeHandler(req, res) {
// req: express.Request
// res: express.Response
}
- This is the only way I found to make it work. But making a call to express() is not without side effects. I would like to avoid that.
var express = require('express');
var { request, response } = express();
/**
*
* @param {request} req
* @param {response} res
*/
function routeHandler(req, res) {
// req: Request
// res: Response
}
Expected behavior:
Expecting require to work similarly to import.
Actual behavior:
Require is not importing the right types.
Related Issues:
#14377
teppeis
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue