I have a set of controller functions for my REST API and I\'m getting lots of the following
error TS7006: Parameter \'req\' implicitly has an \'any\' type.
You can use ES6 style named imports to import only the interfaces you need, rather than import * as express from 'express'
which would include express itself.
First, make sure you have installed the type definitions for express (npm install -D @types/express
).
Example:
// middleware/authCheck.ts
import { Request, Response, NextFunction } from 'express';
export const authCheckMiddleware = (req: Request, res: Response, next: NextFunction) => {
...
};
// server.ts
import { authCheckMiddleware } from './middleware/authCheck';
app.use('/api', authCheckMiddleware);
Currently using TypeScript 2.3.4 and @types/express 4.0.36.