Generic type in useReducer for a returned parameter
问题 I am writing a custom hook to fetch some data from an API. I would like the returned data to be type-safe if possible. Can this be done with generics? type Action = { type: 'PENDING' } | { type: 'SUCCESS'; payload: any } | { type: 'FAIL' }; interface State { isLoading: boolean; isError: boolean; data: any; } const dataFetchReducer = (state: State, action: Action): State => { switch (action.type) { case 'PENDING': return { ...state, isLoading: true, }; case 'SUCCESS': { return { ...state,