I need to set up a very simple store but I'm stuck with this error
Missing return type on function
export interface DataState {
error: string | null;
loaded: boolean;
data: GetIssuesQuery | undefined;
}
const initialState: DataState = {
error: null,
loaded: false,
data: undefined
};
const store = writable<DataState>(initialState);
const dataStore = {
subscribe: store.subscribe,
success: (data: GetIssuesQuery) => {
store.update((state) => {
return {
...state,
loaded: true,
data
};
});
},
failure: (error:string) => {
store.update(() => {
return {
error,
loaded: false,
data: undefined
};
});
}
};
The error is triggered by: success: (data: GetIssuesQuery)
CodePudding user response:
This is probably due to your linter that enforces the hard typing of function's return value.
In your case you will need to tell what type the functions success
and failure
returns. Here it's easy they don't return anything, so simply use void
:
const dataStore = {
subscribe: store.subscribe,
success: (data: GetIssuesQuery): void => {
// ...
},
failure: (error:string): void => {
// ...
}
};