簡體   English   中英

如何繼承 typescript 中的 React SectionList prop 類型?

[英]How to inherit react SectionList prop type in typescript?

我正在圍繞SectionList創建一個包裝器,它應該包含 SectionList 需要的所有道具,加上我的自定義道具。 我該如何配置 typescript?

這是我的嘗試:

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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM