React Native流类型字符串与字符串文字不兼容

时间:2018-11-12 09:42:31

标签: reactjs react-native flowtype

我正在使用一个包装TextInput并添加默认属性的组件,可以完美地工作,但是会出现流错误,因为textContentType和keyboardType必须是文字(它们的可枚举值之一),是否需要帮助程序或类似的东西以避免错误而不写所有可能性?

问题的一个示例:

type Props = { textContentType?: string}
(...)
static defaultProps = { textContentType : 'none'};
(...)
const { textContentType = 'none' } = this.props;
(...)
<TextInput textContentType={textContentType} />

错误:

[flow] Cannot create `TextInput` element because in property `textContentType`: Either string [1] is incompatible with string literal `none` [2]. Or string [1] is incompatible with string literal `URL` [3]. Or string [1] is incompatible with string literal `addressCity` [4]. Or string [1] is incompatible with string literal `addressCityAndState` [5]. Or string [1] is incompatible with string literal `addressState` [6]. Or string [1] is incompatible with string literal `countryName` [7]. Or string [1] is incompatible with string literal `creditCardNumber` [8]. Or string [1] is incompatible with string literal `emailAddress` [9]. Or string [1] is incompatible with string literal `familyName` [10]. Or string [1] is incompatible with string literal `fullStreetAddress` [11]. Or string [1] is incompatible with string literal `givenName` [12]. Or string [1] is incompatible with string literal `jobTitle` [13]. Or string [1] is incompatible with string literal `location` [14]. Or string [1] is incompatible with string literal `middleName` [15]. Or string [1] is incompatible with string literal `name` [16]. Or string [1] is incompatible with string literal `namePrefix` [17]. Or string [1] is incompatible with string literal `nameSuffix` [18]. Or string [1] is incompatible with string literal `nickname` [19]. Or string [1] is incompatible with string literal `organizationName` [20]. Or string [1] is incompatible with string literal `postalCode` [21]. Or string [1] is incompatible with string literal `streetAddressLine1` [22]. Or string [1] is incompatible with string literal `streetAddressLine2` [23]. Or string [1] is incompatible with string literal `sublocality` [24]. Or string [1] is incompatible with string literal `telephoneNumber` [25]. Or string [1] is incompatible with string literal `username` [26]. Or string [1] is incompatible with string literal `password` [27]. (References: [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27])

0 个答案:

没有答案