Я пытаюсь настроить ContextApi и useReducer с машинописным текстом. В моей переменной «issuesInitialState» в useReducer я получаю сообщение об ошибке:
Нет перегрузки, соответствующей этому вызову. Перегрузка 1 из 5, '(reducer: ({state, action}: IssueReducer) => {}, initializerArg: never, initializer ?: undefined): [never, DispatchWithoutAction]', выдает следующую ошибку. Аргумент типа IssuesInitialState не может быть назначен параметру типа never. Перегрузка 2 из 5, '(reducer: ({state, action}: IssueReducer) => {}, initialState: never, initializer ?: undefined): [never, Dispatch]', вызвала следующую ошибку. Аргумент типа IssuesInitialState не может быть назначен параметру типа never. Ts (2769)
// Store.tsx
type Issue = {
closeDate: string | null;
description: string;
issueId: number;
lastEditDate: string | null;
priorityId: string;
projectId: number;
reportDate: string;
statusId: string;
title: string;
userId: number;
};
interface IssuesInitialState {
issues: Issue[];
issue: Issue;
issuesByProject: Issue[];
updateIssue: Issue;
}
const issuesInitialState: IssuesInitialState = {
issues: [],
issue: {
closeDate: "",
description: "",
issueId: 0,
lastEditDate: "",
priorityId: "",
projectId: 0,
reportDate: "",
statusId: "",
title: "",
userId: 0,
},
issuesByProject: [],
updateIssue: {
closeDate: "",
description: "",
issueId: 0,
lastEditDate: "",
priorityId: "",
projectId: 0,
reportDate: "",
statusId: "",
title: "",
userId: 0,
},
};
export const IssuesContext = createContext<{
issuesState: IssuesInitialState;
issuesDispatch: any;
}>({ issuesState: issuesInitialState, issuesDispatch: () => null });
export function StoreProvider({ children }: any): JSX.Element {
const [commentsState, commentsDispatch] = useReducer(
commentsReducer,
commentsInitialState
);
const [issuesState, issuesDispatch] = useReducer(
issuesReducer,
issuesInitialState // where the error is!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
);
// IssuesReducer.ts
interface IssueReducer {
state: IssuesInitialState;
action: {
type: string;
payload: Issue;
};
}
export const issuesReducer = ({ state, action }: IssueReducer): {} => {
switch (action.type) {
case FETCH_ISSUES: