React Native FlatList、样式化组件和 Typescript

Jul*_*ert 5 typescript react-native styled-components react-native-flatlist

我与 styled-components 、 FlatList 和 typescript 进行了一场历史性的持续战斗......到目前为止,我已经能够使其与以下内容一起工作:

const StyledList = styled(FlatList as new () => FlatList<ItemType>)<CustomProps>(props => ({
  .......
}));
Run Code Online (Sandbox Code Playgroud)

这种方法工作得很好,直到我最近进行了一次项目升级,它打破了这种方法。我现在有以下依赖版本:

"typescript": "~4.3.5"

"styled-components": "^5.3.3"

"react-native": "0.64.3"

错误是这样的:

Property 'data' does not exist on type 'IntrinsicAttributes & { ref?: Ref<FlatList< ItemType >> | undefined; key?: Key | null | undefined; } & { theme?: DefaultTheme | undefined; } & { ...; } & { ...; }'.
Run Code Online (Sandbox Code Playgroud)

有人可以提供对此的任何见解吗?最新版本中可能发生了哪些更改styled-componentsreact-native阻止了原始解决方法的工作?

Fel*_*ipe 6

import { FlatList, FlatListProps } from 'react-native';
    
const List = styled(FlatList as new (props: FlatListProps<ItemType>) => FlatList<ItemType>)``;
Run Code Online (Sandbox Code Playgroud)

这个对我有用。