[Fixed] How to get Express type from node_modules?

Issue

I wanted to use JSDoc to annotate my function argument. This is what i do:

import {
    Express
} from '@types/express-serve-static-core';

/**
 * @param {Express} app
 */
function install(app) {
    app.post('/auth/login', (req, res) => {
        // Login
    });
}

export {
    install
}

In VS Code this indeed works

screenshot

However I can’t run my code any longer (it says MODULE_NOT_FOUND) so from here I confused. How to include a type from node_modules?

Please note I know about typescript, but I prefer to avoid it.

Solution

I just aware that this is possible

import express from 'express';

/**
 * @param {express.Express} app
 */
function install(app) {
    app.post('/auth/login', (req, res) => {
        // Login
    });
}

export {
    install
}

Leave a Reply

(*) Required, Your email will not be published