i have a function to get the card component in react:
const getLeagueCardComponent = (value: ELeagueVaritions) => {
if (value === ELeagueVaritions.MATCHES) {
return MatchesCard
}
else if (value === ELeagueVaritions.PLAYERS) {
return PlayersCard
}
else if (value === ELeagueVaritions.TOURNAMENT) {
return TournamentCard
}
};
MatchesCard, PlayersCard, TournamentCard are components that expect elements in props like IMatch[], IPlayerItem[], ITournamentItem[] respectively
and I have a component in which I get a card depending on the type
`
const CardComponent = getLeagueCardComponent(ELeagueVaritions.MATCHES)
return (
<div className={styles.wrapper}>
<h3>{name}</h3>
<CardComponent items={items as IMatch[]} />
</div>
);
`
but I get an error and can’t figure out what I’m doing wrong
Type ‘IMatch[]’ is not assignable to type ‘IMatch[] & IPlayerItem[] &
ITournamentItem[]’. Type ‘IMatch[]’ is not assignable to type
‘IPlayerItem[]’.
Property ‘rateGroups’ is missing in type ‘IMatch’ but required in type ‘IPlayerItem’.ts(2322) index.ts(57, 5): ‘rateGroups’ is declared
here. index.tsx(6, 5): The expected type comes from property ‘items’
which is declared here on type ‘IntrinsicAttributes & IProps & IProps
& IProps’ (property) items: IMatch[] & IPlayerItem[] &
ITournamentItem[]
I have no idea how to solve this problem
Alexander Egorov is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1