阵营本地SectionList具有难以理解流类型的错误
问题描述:
如果在我的代码,这个简单的SectionList定义:阵营本地SectionList具有难以理解流类型的错误
const s = (
<SectionList
renderItem={({ item }) => <Text>abc</Text>}
renderSectionHeader={({ section }) => <Text>abc</Text>}
sections={[{ data: [1, 2, 3], title: 'abc' }]}
/>
);
和流量生成指整个“标记块”(这实际上是将复制粘贴此错误信息VSCode):
[flow] props of React element `SectionList` (This type is incompatible with See also: React element `SectionList`)
这里发生了什么事?
EDIT我使用
flow-bin: 0.56.0
react: 16.0.0
react-native: 0.49.1
EDIT2所以例如可以减少到这个简单的线(在不影响错误信息):
<SectionList sections={[]} />;
EDIT3我刚发现流程投诉了React Native库中定义的几种类型(主要是关于通用typ类型的缺少类型参数) ES)。我想知道是否应该使用较旧的流水版版本。 React Native和流是否有兼容表?
答
我有一个类似的问题,react-native: 0.49.3
和flow-bin: 0.53.0
。从SectionList
源检查类型定义后,得到了它的不用类型的警告如下工作:
type Row = {
name: string,
}
type Section = {
title: string,
data: $ReadOnlyArray<Row>,
}
const mySections: $ReadOnlyArray<Section> = [...] // your data here
<SectionList sections={mySections} />
所以对我来说,关键是用$ReadOnlyArray<T>
,而不是Array<T>
。也许这对你有帮助!
+0
这不会改变我的任何东西。 – Bastian
答
反应有一个内置的流量类型的部分称为SectionBase
:
import type { SectionBase } from 'react-native/Libraries/Lists/SectionList'
type Section = SectionBase<DataType>
因此,基于什么马丁回答你可以这样写:SectionBase<Row>
反应本土您使用的是哪个版本? react-native的代码包含Flow注释,因此您可以通过查看SectionList的代码来准确查看它的期望:https://github.com/facebook/react-native/blob/790eabcdff18470571b3f9a5355c924495015918/Libraries/Lists/SectionList.js –
是的......好吧,我仍然没有线索。不过,我添加了库版本号。 – Bastian
react-native的0.49稳定分支使用'^ 0.53.0'作为流程箱依赖版本。尝试恢复到v0.53.0。 https://github.com/facebook/react-native/blob/0.49-stable/package.json –