I have this line of code:
import {response, request, next} from 'express'
However, i get this error from the typescript compiler, in vscode:
Module '"express"' has no exported member 'next'.
EDIT: I'm importing these types in a file different from my "server.ts", therefore I would like (if possible, of course) a solution that would keep my code lean, and import just what is strictly necessary.
CodePudding user response:
Try importin the express like this:
import express from 'express';
After you created the expressApp, you can use it like this with your endpoint:
this.expressApp.post('endpointName', async (req, res, next) => { })
CodePudding user response:
The correct type for the next
callback argument is NextFunction
:
import { Request, Response, NextFunction} from 'express';
export default function (req : Request , res : Response, next : NextFunction ) {
…
}
CodePudding user response:
Thanks for everyone's feedback.
I installed express with an "npm i express" and the version that came with it was: version 4.18.1
. For this version, I solved the problem by using npm i @types/express
, and, then, using "NextFunction" as the type (e.g.: import {Response, Request, NextFunction} from 'express'
and then const auth = async (req : Request,res : Response , next: NextFunction)
)