In the process of writing a class
, I have noticed that many methods within it share a common function type. To ensure consistency, I want to explicitly define this function type so that specific methods adhere to it.
For example:
interface MyFunctionType {(resource: string | Resource): Something}
My class consists of various methods that align with this interface.
class MyClass {
// ...
someMethod() { /*...*/ }
someMethodThatConforms(resource: string | Resource) {
// ...
return new Something(/*...*/);
}
anotherMethodThatConforms(resource: string | Resource) {
// ...
return new Something(/*...*/);
}
someOtherMethod() { /*...*/ }
// ...
}
I am aware that someMethodThatConforms
and anotherMethodThatConforms
conform to the interface. Now, I want to understand how can I enforce that these methods must adhere to the MyFunctionType
interface (so that any changes to MyFunctionType
will result in errors being thrown)?