Sometimes, we want to create a TypeScript static class.
In this article, we’ll look at how to create a TypeScript static class.
How to create a TypeScript static class?
To create a TypeScript static class, we can create an abstract class.
For instance, we write
export abstract class MyClass {
public static myProp = "Hello";
public static doSomething(): string {
return "World";
}
}
const x = MyClass.doSomething();
to create the MyClass
abstract class with the abstract
keyword.
In it, we add the doSomething
method.
And we call it with MyClass.doSomething
.
Conclusion
To create a TypeScript static class, we can create an abstract class.