For sane reasons, I need to have an object that has functions as key in an object, e.g:
function a() {}
function b() {}
const obj = {
[a]: b
}
The reason for this is that I want to map the values of function a to function b and be able to remember and remove mappings again.
Now I wonder how to write typings for this in TypeScript. If I do
type MapFunctions = { [key: Function]: Function };
I will get the error
An index signature parameter type must be 'string' or 'number'.ts(1023)
But how would I write a type for this?
[a], it's being converted to a string and doesn't remain aFunction:console.log(typeof Object.keys(obj)[0] === 'string');. Your approach does not work in Javascript, and giving it a type declaration does not change that.const a = () => {}; const obj = {[a]: "val"}; console.log(obj[a]);second of all, can you elaborate on why you believe this is not sane?a&bfunctions when they updated