में एक Moment.js ऑब्जेक्ट एनोटेशन निर्दिष्ट करने के लिए कैसे मैं वर्तमान में इसे मौजूदा प्रोजेक्ट पर लागू करके फ्लो सीख रहा हूं और एक क्षण के रूप में फ़ंक्शन पैरामीटर को एनोटेट करना चाहता हूं। जेएस ऑब्जेक्ट्स। जब मैं Moment.JS वस्तुओं के रूप में फ़ंक्शन पैरामीटर टिप्पणी करने की कोशिशफ़्लो
declare class moment$Moment {
static ISO_8601: string;
static (string?: string, format?: string|Array<string>, locale?: string, strict?: bool): moment$Moment;
static (initDate: ?Object|number|Date|Array<number>|moment$Moment|string): moment$Moment;
static unix(seconds: number): moment$Moment;
static utc(): moment$Moment;
...
हालांकि:
flow-typed का उपयोग करते हुए मैं प्रकार मैं तलाश कर रहा हूँ के लिए प्रकट होता है, जिसमें Moment.JS के लिए एक पुस्तकालय परिभाषा स्थापित करने में सक्षम था , फ्लो उन्हें इस तरह पहचानने में विफल रहता है। निम्नलिखित फ़ंक्शन में startDate
और endDate
क्षण हैं। जेएस दिनांक ऑब्जेक्ट्स।
const filterByDateWhereClause = (startDate: Moment, endDate: Moment): string =>
^^^^^^ identifier `Moment`. Could not resolve name
प्रवाह के साथ यह और भी संभव है:
const filterByDateWhereClause = (startDate: Moment, endDate: Moment): string => {...};
प्रवाह निम्न त्रुटि देता है? या क्या मुझे type
को क्षण के लिए डुप्लिकेट करने की आवश्यकता है। जेएस ऑब्जेक्ट फ्लो-टाइप द्वारा प्रदान की गई लाइब्रेरी परिभाषा में से एक के समान है? मैं ऐसा नहीं करना चाहूंगा क्योंकि libdef काफी लंबा है।
declare class Moment {
static ISO_8601: string;
static (string?: string, format?: string|Array<string>, locale?: string, strict?: bool): moment$Moment;
static (initDate: ?Object|number|Date|Array<number>|moment$Moment|string): moment$Moment;
static unix(seconds: number): moment$Moment;
static utc(): moment$Moment;
...
const filterByDateWhereClause = (startDate: Moment, endDate: Moment): string => {...};
मैं क्या याद आ रही है:
उदाहरण के लिए?
'पल $ पल' मेरे लिए काम नहीं करेगा, शायद क्योंकि मैं वेबपैक का उपयोग कर रहा हूं इसलिए कोई वैश्विक नामस्थान नहीं है? दो आयात विधियों ने काम किया। – clhenrick
वेबपैक का प्रवाह प्रवाह पर असर नहीं होना चाहिए - मुझे यकीन नहीं है कि वैश्विक प्रकार आपके लिए क्यों काम नहीं कर रहा है लेकिन यह ठीक है क्योंकि आपको वास्तव में इसका उपयोग नहीं करना चाहिए ... CONTRIBUTING.md में प्रवाह-टाइप के लिए दस्तावेज़, यह libdef लेखकों को ग्लोबल्स को उपसर्ग करने के लिए कहता है जो वैश्विक होने के लिए नहीं हैं: (https://github.com/flowtype/flow-typed/blob/316320bf2cbc48a9447e053272a5c113e6e26a8c/CONTRIBUTING.md#prefix-global-variables -यह-वास्तव में-मतलब-से-होने-वैश्विक नहीं है), इसलिए आपको इसका उपयोग नहीं करना चाहिए :) –