I want to sort of dynamically create an instance of an interface that has a key that is specified dynamically, through a function parameter
effectively I want to do something simple like this:
function callWith(key, value) {
return fnWithKeyValue =>
fnWithKeyValue({ [key]: value });
}
(What I specifically want this for is a React HOC with the ability to set a dynamic property, but I've tried to simplify above)
For instance, lets say I there is some function more or less beyond my control:
interface ValueType {
magicValue: number;
}
function MyCallback(v: ValueType) {
}
And so I want this to successfully compile:
callWith('magicValue', 123)(MyCallback);
but I want this to fail to compile:
callWith('normalValue', 123)(MyCallback);
Is this even possible with TypeScript?
MyCallbackand do the check inside it?