I'm using immer with generic, here is a minimal example:
function foo<T extends string>(record: Record<T, boolean>, key: T) {
return produce(record, (draftState) => {
draftState[key] = true;
});
}
but this example results in typescript error
Type 'T' cannot be used to index type 'Draft<Record<T, boolean>>'.
My question is, how can I access value by key in a generic record wrapped in Draft
or Immutable
type without causing error above?