如何在打字稿中继承 React SectionList 道具类型?
How to inherit react SectionList prop type in typescript?
我正在围绕 SectionList 创建一个包装器,它应该采用 SectionList 采用的所有道具,加上我的自定义道具。我如何为此配置打字稿?
这是我的尝试:
import React from 'react';
import { SafeAreaView, SectionList } from 'react-native';
interface EnhancedSectionListProps {
...SectionListProps; // this obviously won't compile, but shows what I'm trying to achieve
enhancedProp: string;
}
export const EnhancedSectionList = (props: EnhancedSectionListProps) => {
return (
<SafeAreaView>
<SectionList {...props} />
// use my `enhancedProp` here
</SafeAreaView>
);
};
PS:我们不使用prop-types
库。
要完成任务,您需要扩展 界面。例如:
interface EnhancedSectionListProps extends SectionListProps {
enhancedProp: string;
}
我正在围绕 SectionList 创建一个包装器,它应该采用 SectionList 采用的所有道具,加上我的自定义道具。我如何为此配置打字稿?
这是我的尝试:
import React from 'react';
import { SafeAreaView, SectionList } from 'react-native';
interface EnhancedSectionListProps {
...SectionListProps; // this obviously won't compile, but shows what I'm trying to achieve
enhancedProp: string;
}
export const EnhancedSectionList = (props: EnhancedSectionListProps) => {
return (
<SafeAreaView>
<SectionList {...props} />
// use my `enhancedProp` here
</SafeAreaView>
);
};
PS:我们不使用prop-types
库。
要完成任务,您需要扩展 界面。例如:
interface EnhancedSectionListProps extends SectionListProps {
enhancedProp: string;
}