I have a simple scenario that resembles the following and is functioning perfectly:
export interface CustomState {
someBool: boolean;
status: string;
}
function checkStateDifference<K extends keyof CustomState>(props: { stateKey: K, value: CustomState[K] }) {
return this.state[props.stateKey] !== props.value;
}
I wanted to abstract this into its own type so I could reuse it in another function, but I encountered an error in my IDE
Generic type 'CustomState' requires 1 type argument(s)
. Why does this not occur when defined inline and how can I resolve it?
type StateComparisonProps<K extends keyof CustomState> = { stateKey: K, value: CustomState[K] };
function checkStateDifference(props: StateComparisonProps) {
return this.state[props.stateKey] !== props.value;
}
EDIT: corrected copy/paste error