I want to sort my state and delete exact name, i do it with map&filter, they should return the same state, but with a few changes. But TypeScript threw an error 2322
I use TS+Redux Toolkit
This is the reducer
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
);
}
And this is the InitialState interfaces and others
interface InitialTeamState {
teams: TeamsState[];
}
const initialState: InitialTeamState = {
teams: []
};
interface IEmployee {
name?: string;
birthDate?: number;
citizenship?: string;
adress?: 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;
};
And the error : 