Can TypeScript define an interface that will only be applied to methods starting with a specific word and enforce them to have a certain return type? I had the idea of:
interface IPattern {
[k: 'handle' + string]?: () => SomeClass
}
This would mean that a class implementing IPattern would need to have methods starting with 'handle' returning a SomeClass object, while other methods would not, for example:
class ForcedClass implements IPattern{
foo(): number; // ok
handleFoo(): SomeClass; // ok
handleBar(): number; // error
}
Although I could use an abstract class containing all the required methods, it would be tedious to create one for each implementation given that the handle + something
combination is used in multiple scenarios;