Static members with types
📖 Scenario: You are creating a simple class to keep track of how many times a certain action happens across all instances.
🎯 Goal: Build a TypeScript class with a static member that counts how many times a method is called on any instance.
📋 What You'll Learn
Create a class called
ActionCounterAdd a static number property called
count initialized to 0Add a method called
performAction that increases count by 1Use proper TypeScript types for the static member and method
Print the static
count after calling performAction multiple times💡 Why This Matters
🌍 Real World
Static members are useful to keep track of data shared across all objects, like counting total users logged in or tracking global settings.
💼 Career
Understanding static members helps in designing classes that manage shared data efficiently, a common task in software development.
Progress0 / 4 steps