I am using typescript in a react project.
I am getting the following error.
Argument of type '{ teams: { home: { name: string; }; away: { name: string; }; }[]' is not assignable to parameter of type 'Fixtures[] | (() => Fixture[])'.
My type definitions and use in a react component are below.
type Team = {
name: 'Liverpool' | 'Man Utd';
};
type Fixtures = {
teams: {
home: {
name: Team;
},
away: {
name: Team;
},
winner: Team;
};
};
const initialFixtures = [
{
teams: {
home: {
name: 'Liverpool',
},
away: {
name: 'Man Utd',
},
},
winner: 'Liverpool',
},
];
I am then using this in my React component like below but
// Error is in `initial fixtures`
const [fixtures, updateFixtures] = useState<Fixtures[]>(initialFixtures);
Can anyone see what I am doing wrong? I can't see where it is inferring it to be a string when I have said it is a Team.