@types/xxxx
und hatte Probleme.Definitions by:
in index.d.ts
), damit sie es können Antworten.Ich habe das aktuelle Problem mit @types/express 4.11.1 & TSC 2.8.3.
Der folgende Code kann nicht kompiliert werden:
function aMiddleware(req: Request, res: Response, next: NextFunction) {
next();
}
app.get('/foo/bar', aMiddleware);
Ich bekomme folgenden Fehler:
TS2345: Argument of type '(req: Request, res: Response, next: NextFunction) => void' is not assignable to parameter of type 'RequestHandlerParams'.
Type '(req: Request, res: Response, next: NextFunction) => void' is not assignable to type '(RequestHandler | ErrorRequestHandler)[]'.
Property 'includes' is missing in type '(req: Request, res: Response, next: NextFunction) => void'.
Hallo Jimmy,
Sie müssen so importieren ...
import { Express, Request, Response, NextFunction } from 'express';
const express = require('express');
const app: Express = express();
function aMiddleware(req: Request, res: Response, next: NextFunction) {
next();
}
app.get('/foo/bar', aMiddleware);
Der Grund dafür ist, dass Request
, Response
, NextFunction
von Node.js nicht mit Express identisch sind.
Hoffe das hilft.
Danke, das werde ich mal ausprobieren!
Das funktioniert super. Vielen Dank noch einmal.
Hilfreichster Kommentar
Hallo Jimmy,
Sie müssen so importieren ...
Der Grund dafür ist, dass
Request
,Response
,NextFunction
von Node.js nicht mit Express identisch sind.Hoffe das hilft.