TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
TypeScript / Chapter 28 of 60~12 min • Beginner
Chapter 28TypeScript

Typed classes and access modifiers

TypeScript classes support typed fields, constructors and visibility modifiers such as public and private. readonly prevents reassignment through the type system after initialization. These features help page objects expose actions while organizing internal state.

How it works

Step-by-step walkthrough

  1. Create a typed class
  2. Initialize a field
  3. Call a public method

Example

TypeScript
class Config {
  constructor(private readonly browser: string) {}
  describe(): string { return this.browser; }
}
console.log(new Config('chromium').describe());
Expected result: chromium
💡 Point to remember
TypeScript private is not the same as JavaScript # runtime private fields.

✎ Your practice task

Try accessing browser directly from outside the class.

Knowledge check

Which modifier prevents normal reassignment after initialization?

🌐 Continue learning