Skip to content

[Salsa JSDoc] Using express types with require #21551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ekulabuhov opened this issue Feb 1, 2018 · 2 comments
Closed

[Salsa JSDoc] Using express types with require #21551

ekulabuhov opened this issue Feb 1, 2018 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ekulabuhov
Copy link

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

  1. 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
}
  1. 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    
}
  1. 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

@mhegazy
Copy link
Contributor

mhegazy commented Feb 1, 2018

Ideally all should work.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Mar 9, 2018

@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label Mar 9, 2018
@mhegazy mhegazy closed this as completed Mar 9, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants