I'm working on a new library which will contain a set of callback functions. I want to implement a sort of "namespace" feature so interfaces and callback chains don't get so overwhelming.
My base callback / namespace with callback type looks like this:
type AnyFunction = (...args: any) => void;
type DefinedTypeMap = {
[key: string]: AnyFunction | DefinedTypeMap;
};
Where the then extended interfaces could look like this:
interface IMyCallbackFunctions extends DefinedTypeMap {
namespace: {
func: (msg: string) => void;
};
root: (msg: string) => void;
otherRoot: (msg: string) => void;
}
I'm working on a class function that will ONLY accept keys on the object if that value is an AnyFunction
type ( Not a nested namespace ).
As the interfaces are defined by the developer using the library ( as long as they extend the required interface ) the accepted function parameters in this case would ONLY be "root" | "otherRoot"
I have tried Omit<T, K>
as well as looking high and low on stack overflow for a solution ( to no avail ).
This library uses Typescript@4.5.5
The current function (which does not support the in progress namespace feature) looks like this:
on<E extends keyof P2PConnectionEventMap<T>, F extends P2PConnectionEventMap<T>[E]>(event: E, callback: F) => void
and should be modified to only allow the event
param to accept keys where the values on the interface are of the callback type not the object type.
Thanks in advance for the help, this is making me want to pull my hair out.