0

我正在尝试使用 flow-bin 0.158.0 在 React-Native 0.66.1 上正确键入 SectionList 调用

我有以下代码:

// @flow
import React from 'react';
import type {Node} from 'react';
import {SafeAreaView, SectionList} from 'react-native';

type Props = {
  sections: $ReadOnlyArray<{
    title: string,
    data: $ReadOnlyArray<{a: string}>,
  }>,
};

const App: (props: Props) => Node = ({sections}) => {
  return (
    <SafeAreaView>
      <SectionList sections={sections} renderItem={({item}) => null} />
    </SafeAreaView>
  );
};

export default App;

当我运行 flowjs 检查时,出现 20 个错误:

Cannot create SectionList element because property ItemSeparatorComponent is missing in object type [1] but exists in
SectionBase [2] in type argument SectionT. [prop-missing]


Cannot create SectionList element because property key is missing in object type [1] but exists in SectionBase [2] in
type argument SectionT. [prop-missing]

Cannot create SectionList element because property keyExtractor is missing in object type [1] but exists in
SectionBase [2] in type argument SectionT. [prop-missing]


Cannot create SectionList element because property renderItem is missing in object type [1] but exists in
SectionBase [2] in type argument SectionT. [prop-missing]

这是一个屏幕截图: 错误截图

错误指向我这里: https ://github.com/facebook/react-native/blob/1465c8f3874cdee8c325ab4a4916fda0b3e43bdb/Libraries/Lists/VirtualizedSectionList.js#L43

SectionBase 定义中的 key、renderItem、ItemSeparatorComponent 和 KeyExtractor 都设置为可选。

那么我的sections 道具的正确类型定义是什么?

4

0 回答 0