I needed to organize my state and remove specific names using map and filter functions. Although these should return the same state with only a few modifications, TypeScript threw an error 2322
The setup I am using is TS+Redux Toolkit
This is how the reducer looks:
removeName(state, action: PayloadAction<IAction>) {
return state.teams.map((i) =>
i.leadName === action.payload.leadName
? i.employees.filter((n) => n.name != action.payload.name)
: i
);
}
Here are the InitialState interfaces and other declarations:
interface InitialTeamState {
teams: TeamsState[];
}
const initialState: InitialTeamState = {
teams: []
};
interface IEmployee {
name?: string;
birthDate?: number;
citizenship?: string;
address?: string;
teamLead?: string;
position?: string;
phoneNumber?: number | string;
mail?: string;
workMail?: string;
whenHired?: string;
registration?: number | string;
}
interface TeamsState {
id: number;
leadName: string;
employees: IEmployee[];
}
interface IAction {
name?: string;
leadName?: string;
};
Lastly, the error message received: