Is there a way to achieve different types for the nested K
type within a type like MyType
? Here's an example:
type Config<K> = {
value: K;
onUpdate: (value: K) => void;
}
type MyType<F extends string> = {
[K in F]: <V>() => Config<V>;
}
// Desired functionality
const hello: MyType<'setup1'|'setup2'> = {
setup1: () => ({
value: { hello: 'world' },
onUpdate: record => console.log(record.hello),
}),
setup2: () => ({
value: { goodbye: 'world' },
onUpdate: record => console.log(record.goodbye),
}),
};
Encountering the error message
Type '{ hello: string; }' is not assignable to type 'V'. 'V' could be instantiated with an arbitrary type which could be unrelated to '{ hello: string; }'.(2322)
when attempting this.