Javascript 财产';x';类型'中缺少;{}';但类型为';拾取<;“接口”;x"&燃气轮机';。TS2741

Javascript 财产';x';类型'中缺少;{}';但类型为';拾取<;“接口”;x"&燃气轮机';。TS2741,javascript,reactjs,typescript,types,react-redux,Javascript,Reactjs,Typescript,Types,React Redux,我正试图通过connect将一些内容从redux存储区传递到组件。这是我的代码: 家长: export const MainPage = ( { count, handleIncrementClick, selectedOfferId, }: MainPageProps, ): React.ReactElement => { const handleClick = (): Function => handleIncrementClick(count

我正试图通过
connect
将一些内容从redux存储区传递到组件。这是我的代码:

家长:

export const MainPage = (
  {
    count,
    handleIncrementClick,
    selectedOfferId,
  }: MainPageProps,
): React.ReactElement => {
  const handleClick = (): Function => handleIncrementClick(count + 1);
  return (
    <div>
      <h1 data-testid="FirstH1">{`Selected offer: ${selectedOfferId}`}</h1>
      <button onClick={handleClick} type="button">
        {`Klikłeś  ${count}  razy`}
      </button>
      <OffersContainer /> {/* It throws the error here */}
    </div>
  );
};
  • 组成部分:

     export const OffersComponent = ({ offersDataSet }: OffersPropsInterface): ReactElement => (
       <>
         {offersDataSet.map(({
           id, firstName, city, price, image, description,
         }): React.ReactElement => (
           <FlexWrapper key={id.$oid}>
             <OfferContainer
               id={id}
               firstName={firstName}
               city={city}
               price={price}
               image={image}
               description={description}
             />
           </FlexWrapper>
         ))}
       </>
     );
    
    OfferPropsInterface:

    export interface OffersPropsInterface {
      offersDataSet: OfferPropsInterface[];
    }
    
    export interface OfferPropsInterface {
      id: {'$oid': string};
      firstName: string;
      city: string;
      price: number;
      image: string;
      description: string;
    }
    
    这似乎是一个简单的问题,但出于某种原因,我出现了以下错误:

    类型“{}”中缺少属性“offersDataSet”,但类型“Pick”中需要属性“offersDataSet”。TS2741


    为什么呢?我不是渲染组件,而是渲染容器,它只需要通过redux提供的
    offersDataSet
    作为数组。如何使
    提供的数据集
    是必需的,但仅用于redux,而不用于渲染?还是问题完全不同了?

    好吧,我很愚蠢。我将redux数据分配给了一个错误的名称。在这里:

    const mapStateToProps = (state: globalStateType) => ({
       dataset /* This should've been offersDataSet.*/: state.offersDataSet,
     //^^^ offersDataSet
    });
    
    现在我知道为什么我什么都需要类型了

    const mapStateToProps = (state: globalStateType) => ({
       dataset /* This should've been offersDataSet.*/: state.offersDataSet,
     //^^^ offersDataSet
    });