如果有这个简单的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`)
这里发生了什么?
编辑 我在用
flow-bin: 0.56.0
react: 16.0.0
react-native: 0.49.1
编辑2 所以这个例子可以简化为这个简单的行(不影响错误信息):
<SectionList sections={[]} />;
编辑3 我刚刚发现 flow 提示 React Native 库中定义的几种类型(主要是关于缺少泛型类型的类型参数)。我想知道我是否应该使用旧的 flow-bin 版本。是否有 React Native 和 flow 的兼容性表?
最佳答案
我遇到了类似的问题 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>
.或许这对你有帮助!
关于list - React Native SectionList 有无法理解的流类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46591780/