As a beginner in TypeScript, I recently discovered that static methods are not supported in interfaces. However, I found a workaround explained in Val's answer. The workaround works fine if your class contains only static methods. But if you have a combination of static and non-static methods in your class, you might encounter this error:
Class 'MyClass' incorrectly implements interface 'sampleInterface'.
Property 'staticFunction' is missing in type 'MyClass' but required in type 'sampleInterface'
Do you have any suggestions on how to address this issue?
export function staticDecorator<T>() {
return (constructor: T) => {};
}
interface sampleInterface {
staticFynction(/*something*/): promise<void>;
nonStaticFynction(/*something*/): promise<void>;
}
@staticDecorator()
class MyClass implements sampleInterface {
public static staticFynction(/*something*/): promise<void>{
//something
}
public nonStaticFynction(/*something*/): promise<void>{
//something
}
}