P
P
Polina Titova2022-02-08 17:04:17
React
Polina Titova, 2022-02-08 17:04:17

How to add a missing required property to a type?

The program gives an error:

Свойство "onChangeFilter" отсутствует в типе "{ tickets: Tickets; filterOrder: string; }" и является обязательным в типе "{ onChangeFilter(filterOrder: string): void; }".

and refers to the App.tsx file with a red underline MainScreen:

App.tsx file:
const mapToStateProps = ({ tickets, filterOrder }: State) => ({
  tickets,
  filterOrder,
});

const connector = connect(mapToStateProps);

type PropsFromRedux = ConnectedProps<typeof connector>;

function App(props: PropsFromRedux): JSX.Element {
  const { tickets, filterOrder } = props;

  return (
    <MainScreen tickets={tickets} filterOrder={filterOrder} />
  );
}


As I understand it, props is expected, which is not passed to MainScreen:

Main-screen.tsx file:
type MainScreenProps = {
  tickets: Tickets;
  filterOrder: string;
};


But onChangeFilter is not taken from props, we create it ourselves:
const mapDispatchToProps = (dispatch: Dispatch<Actions>) => ({
  onChangeFilter(filterOrder: string) {
    dispatch(changeFilter(filterOrder));
  },
});


How to find out the expected and required properties, and how to fix the error?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question