I am facing a challenge with an object that contains multiple method names which are not known at compile time. The signature of these methods always remains the same, but I am unsure about how to handle this scenario. I attempted to utilize an index type solution as shown below:
interface List<T> extends Array<T> {
[key: string]: (...arg0: any[]) => List<T>
[key: string]: () => List<any>
each(fn: Function): void
each(...args: any[]): void
toArray(): T[]
}
Unfortunately, TypeScript throws an error stating it cannot accommodate other method signatures within this structure:
Property 'each' of type '{ (fn: Function): void; (...args: any[]): void; }' is not assignable to string index type '(...arg0: any[]) => List'.
This may be an unconventional requirement, but I am in need of a solution. How can this specific issue be addressed in TypeScript?