This post shows how to create a static property and static methods in TypeScript with an example.
TypeScript allows creating static members of a class, those that are visible on the class itself rather than on the instances. Static members are referenced by the class name.
In below example, we have two static class members, one is static property and another static method:
class Employee{
static fullName: string;
static getFullName(){
return Employee.fullName;
}
}
// create Employee class object
Employee.fullName = 'Ramesh Fadatare';
console.log(Employee.getFullName());
Output:
Ramesh Fadatare
Comments
Post a Comment