Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redux ConnectedProps is of type never

I am trying to connect a component to my Redux store using the official documentation guide, but the props connected appear to be of type never.

Here is my code so far:

Type definitions:

export interface CardInterface {
    id: string;
    titulo: string;
    descripcion: string;
    url?: string;
    fecha: Date;
}

export type CardsState = Readonly<{
    cards: CardInterface[];
}>;

The actual component:

import * as React from 'react';
import { connect, ConnectedProps } from 'react-redux';

const mapStateToProps = (state: CardsState) => ({
    cards: state.cards,
});

const connector = connect(mapStateToProps, null);

type Props = ConnectedProps<typeof connector>;

const CardList: React.FC<Props> = ({ cards }) => {
    return (
        <div className="grid-container container">
            {cards.map((card: CardInterface) => (
                <Card
                    title={card.titulo}
                    description={card.descripcion}
                    image={card.url}
                />
            ))}
        </div>
    );
};

export default connector(CardList);

When I try to iterate over the cards, the linter identifies the cards prop as never:

enter image description here

Has anyone else ran into this problem? Thank you very much.

like image 217
Alejandro Otero Gómez Avatar asked Jul 30 '20 18:07

Alejandro Otero Gómez


1 Answers

Omitting the unused mapDispatchToProps argument should fix this Typescript error:

const connector = connect(mapStateToProps); //instead of passing null 

Apparently it's a known issue

like image 64
itaydafna Avatar answered Oct 03 '22 05:10

itaydafna