I am trying to implement a useReducer hook in typescript like so:
export interface ScannerState {
showAction: boolean;
data?: QRData;
}
export function mergeObjReducer<S extends object>(state: S, changes: Partial<S>): S {
return { ...state, ...changes };
}
const [scannerState, setScannerState] = useReducer(
mergeObjReducer,
{ data: undefined, showAction: false },
);
// here typescript doesn't provide me with suggestions of the keys of the object.
setScannerState({data: "some data value"});
//expecting the above line to suggest me keys of data or showAction currently ts doesnt provide me with any suggestions.
How do i fix the type definitions so that typescript understands what all the keys are of the value that useReducer expects.
I hope this makes sense, let me know if this needs further clarification(s).