I am looking to declare an interface in typescript that is extensible through an indexer, allowing for the dynamic association of additional functions. However, I also want sub properties within this interface that can refer back to those indexed functions by name. Do you think this is achievable with the capabilities of the TS compiler? I haven't been able to stump it yet, but I'm curious if anyone has any ideas.
interface CustomInterface {
someProp: {
[x: string]: keyof this; // Attempting to refer to indexed keys here
};
[x: string]: Function; // Clients can provide their own functions here
}
// Example of how to use it
let myCustomInterface: CustomInterface = {
bar: {
validFuncName: "someFunc", // This should work
invalidFuncName: "thisIsNotAFunction" // This should trigger an error
},
someFunc: () => {}
}