@types/xxxx
وواجهت مشاكل.Definitions by:
في index.d.ts
) حتى يتمكنوا من ذلك رد.أواجه المشكلة الحالية باستخدام @ types / express 4.11.1 & TSC 2.8.3.
لا يمكن ترجمة الكود التالي:
function aMiddleware(req: Request, res: Response, next: NextFunction) {
next();
}
app.get('/foo/bar', aMiddleware);
أحصل على الخطأ التالية:
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'.
مرحبا جيمي ،
تحتاج إلى استيراد مثل هذا ...
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);
السبب هو Request
، Response
، NextFunction
من Node.js ليست مثل Express.
أتمنى أن يساعدك هذا.
شكرًا ، سأجرب ذلك!
هذا يعمل بشكل رائع. شكرا جزيلا مرة أخرى.
التعليق الأكثر فائدة
مرحبا جيمي ،
تحتاج إلى استيراد مثل هذا ...
السبب هو
Request
،Response
،NextFunction
من Node.js ليست مثل Express.أتمنى أن يساعدك هذا.