export type ValuesType<T> = T[keyof T];
Just a small generic so I can do less typing. Otherwise it would've looked like this everywhere.
type StateEnumType = (typeof StateEnum)[keyof typeof StateEnum];
Example usage in a React useReducer
.
const PointerStateEnum = {
isMouseDown: 'isMouseDown',
isMouseUp: 'isMouseUp',
} as const;
type PointerStateEnumType = ValuesType<typeof PointerStateEnum>;
const initialState = {
pointerState: <PointerStateEnumType | null> null;
};
dispatch({
type: 'SET_POINTER_STATE',
payload: PointerStateEnum.isMouseDown,
});