I trying to set up ContextApi & useReducer with typescript. On my "issuesInitialState" variable in useReducer, I get the error:
No overload matches this call. Overload 1 of 5, '(reducer: ({ state, action }: IssueReducer) => {}, initializerArg: never, initializer?: undefined): [never, DispatchWithoutAction]', gave the following error. Argument of type 'IssuesInitialState' is not assignable to parameter of type 'never'. Overload 2 of 5, '(reducer: ({ state, action }: IssueReducer) => {}, initialState: never, initializer?: undefined): [never, Dispatch]', gave the following error. Argument of type 'IssuesInitialState' is not assignable to parameter of type 'never'.ts(2769)
code:
// 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: