में एक्सप्रेस अनुरोध वर्ग का विस्तार कर रहा हूं, मैं फ़्लो का उपयोग करके एक नोडजेएस ऐप बना रहा हूं, और मुझे अन्य क्षेत्रों को समायोजित करने के लिए एक्सप्रेस $ अनुरोध के लिए डिफ़ॉल्ट एक्सप्रेस एनोटेशन का विस्तार करना होगा, जैसे कि .user और .session।फ्लो
दुर्भाग्यवश, जब मैं ऐसा करने की कोशिश करता हूं और इस नए अनुरोध प्रकार को स्वीकार करता हूं, फ्लो फ्रीक्स बाहर करता है और मुझे यकीन नहीं है कि मैं क्या गलत कर रहा हूं।
से प्रवाह टाइप एक्सप्रेस के लिए मूल कोड है:
declare class express$Request extends http$IncomingMessage mixins express$RequestResponseBase {
....
}
declare type express$Middleware =
((req: express$Request, res: express$Response, next: express$NextFunction) => mixed) |
((error: ?Error, req: express$Request, res: express$Response, next: express$NextFunction) => mixed);
इसलिए मैंने सोचा कि मैं सिर्फ एक्सप्रेस $ अनुरोध का विस्तार होगा और फिर मेरी मिडलवेयर के सभी नए गुणों के साथ काम करना चाहिए, है ना?
function
This type is incompatible with
union: function type(s): web/src/index.js:113
Member 1:
function type: flow-typed/npm/express_v4.x.x.js:97
Error:
web$Request: web/src/index.js:114
This type is incompatible with the expected param type of
express$Request: flow-typed/npm/express_v4.x.x.js:97
Member 2:
function type: flow-typed/npm/express_v4.x.x.js:98
Error:
web$Request: web/src/index.js:114
This type is incompatible with an argument type of
null: flow-typed/npm/express_v4.x.x.js:98
किसी को समझा सकते हैं क्या यहाँ पर जा रहा है और इसे ठीक करने के है:
declare class web$Request extends express$Request {
user: any,
isAuthenticated(): boolean,
session: {
loginForwardUrl: ?string,
},
}
const authenticationMiddleware: express$Middleware = (
req: web$Request, res, next
): mixed => {
if (req.isAuthenticated()) {
return next();
}
req.session.loginForwardUrl = req.originalUrl;
return res.redirect('/auth/login/google');
}
दुर्भाग्य से, इस सुपर जटिल त्रुटि पैदावार?
धन्यवाद!
दौलत, क्रूर - चाहते हैं कि प्रवाह इस बेहतर समर्थन करेंगे। धन्यवाद! – user358829