100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
TypeScript

Static Members in TypeScript

Define properties and methods that belong to the class itself rather than to individual instances, using the static keyword.

Classes & OOPIntermediate6 min readJul 8, 2026
Analogies

1. Introduction

Most class members belong to individual instances — each object created with 'new' has its own copy. Static members are different: they belong to the class itself, shared across all instances, and are accessed through the class name rather than through an object reference.

🏏

Cricket analogy: Each player has their own individual stats like personal strike rate, but a team's total 'matchesPlayed' this season is shared across the whole squad, accessed via the team name rather than any one player, like a static member.

2. Syntax

typescript
class ClassName {
  static staticProperty: Type = value;

  static staticMethod(): ReturnType {
    // access other static members via ClassName.member
  }
}

ClassName.staticProperty;
ClassName.staticMethod();

3. Explanation

A static member is declared with the static keyword and is accessed via the class name (e.g. Counter.getCount()), never via an instance (e.g. NOT counterInstance.getCount()). Static members are useful for data or behavior that is shared across every instance, such as a running count of how many objects were created, configuration constants, or factory/helper methods.

🏏

Cricket analogy: A static member is declared like static totalMatches = 0 and accessed as Team.totalMatches, never as squadInstance.totalMatches, useful for shared data like the count of matches a franchise has played across all seasons.

Static members can also combine with access modifiers and readonly, e.g. private static count = 0 restricts direct external access while still sharing the value across all instances, and static readonly maxAllowed = 5 creates a class-wide constant.

🏏

Cricket analogy: private static totalRunsScoredLeagueWide = 0 restricts direct outside access while still sharing the tally across every Team instance, and static readonly maxOversPerInnings = 50 creates a league-wide constant.

Static members belong to the class itself, not to instances. Inside a static method, you refer to other static members using the class name (e.g. Counter.count), not 'this', because a static method has no instance context — it can be called without ever creating a single instance of the class.

4. Example

typescript
class Counter {
  private static count = 0;
  static readonly maxAllowed = 5;

  constructor() {
    Counter.count++;
  }

  static getCount(): number {
    return Counter.count;
  }
}

new Counter();
new Counter();
new Counter();

console.log(Counter.getCount());
console.log(Counter.maxAllowed);

5. Output

text
3
5

6. Key Takeaways

  • static members belong to the class itself, shared across all instances.
  • Access static members through the class name, e.g. ClassName.member, not through an instance.
  • Static methods have no 'this' referring to an instance; they use the class name to reach other static members.
  • static combines with access modifiers (private static) and readonly (static readonly) for shared, protected constants.
  • A static member's value updates once and is visible to every instance immediately, since there is only one copy.

Practice what you learned

Was this page helpful?

Topics covered

#TypeScript#TypeScriptProgrammingStudyNotes#Programming#StaticMembersInTypeScript#Static#Members#Syntax#Explanation#StudyNotes#SkillVeris