I am looking to design an interface for an object that can have optional properties with specific names, as well as accept properties with arbitrary names. Here is my approach:
interface CallBack {
onTransition?(): any; // option A
[key: string]: () => any; // option B
}
However, when testing this setup, I encountered the following error:
Property 'onBeforeTransition' of type '(() => any) | undefined' is not assignable to string index type '() => any'
.
I understand that this essentially means the same thing as:
interface CallBack {
[key: string]: () => any;
}
The reason behind wanting this feature is to improve editor assistance when defining callbacks. Is there a way to achieve this desired functionality?