Not sure how best to explain this but I have a "config" object.
const CONFIG = {
hr: {
prop1: "prop1val1",
},
div: {
prop1: "prop1val2",
prop2: 'prop1val1'
},
};
The values objects share some of the keys. In the case above, its prop1
I want to create a function which takes a generic T extends keyof typeof CONFIG
and types an onChange function which can be used to set any of the overlapping/intersecting keys
this is what I have
type TConfig = typeof CONFIG;
type TConfigKeys = keyof TConfig;
type TConfigValues<T extends TConfigKeys> = TConfig[T];
type FnParams<T extends TConfigKeys> = {
readonly onChange: (value: Partial<TConfigValues<T>>) => void;
};
const fn = <T extends TConfigKeys>({ onChange }: FnParams<T>) =>
onChange({
prop1: "solid",
});
However I get an error
Argument of type '{ prop1: "solid"; }' is not assignable to parameter of type 'Partial<TConfigValues<T>>'
which I don't understand what the issue really is