Sidebar link will be added once content is approved. Not indexed by search engines.
Curriculum . TypeScript
Learn TypeScript for Playwright - 5 chapters, 6 modules
TypeScript is what every serious Playwright codebase ships in. Once your JavaScript is solid,
adding a type system gives you autocomplete on every locator, refactor safety on every page
object, and a compiler that catches half your bugs before the browser opens. This page covers
chapters 18 to 22 of our internal TS track and groups the topics into six modules - from
tsconfig.json to generics and abstract classes. Every module points at a TTA
project (the V1 framework, the TTACart suite) where you actually apply the patterns. We summarise the
curriculum here, not the source - write the answers yourself.
5
Chapters covered
Chapters 18-22 of the internal track, six teaching modules.
38
Sub-topics
From strict mode to readonly parameter properties.
60
Exercises
Approx count of write-the-type, infer-the-shape, narrow-this-union drills.
01TS setup + basics
Topics 175-178. Get the compiler running, write the first hello-world, and learn the seven type annotations you will see in 80 percent of Playwright code.
Sub-topics covered
tsc install + inittsconfig.jsonstrict modetarget + moduleesModuleInteropHello world compilenumber / string / booleanarrays + tuplestype vs interface
Topics 179-183. Once string and number click, the next level is unknown, narrowing, and the typed array methods that come for free.
Sub-topics covered
any vs unknownnever + voidunion + intersectionliteral typestype narrowingtypeof / instanceof guardsin operator narrowingdiscriminated unionsarray.filter type predicates
flowchart TD
X[x: string | number] --> G{typeof x === 'string'?}
G -- yes --> S[narrowed to string -> .toUpperCase ok]
G -- no --> N[narrowed to number -> .toFixed ok]
Type narrowing - control flow narrows the typeany vs unknown - both top types, only one is safe
flowchart LR
P1[Cat: kind, meow] --> S[structural check]
P2[CatLike: kind, meow] --> S
S --> EQ[TS treats them as the SAME type]
Structural typing - shape matters, name does not
Exercises typical for this module
Migrate a callback API that uses any for the response into one that uses unknown, then narrow it with typeof and in before using it.
Write a filterNonNull<T> that turns Array<T | null> into Array<T> using a type predicate (x): x is T => x !== null.
Build a discriminated union for a test result: { status: 'pass'; ms: number } | { status: 'fail'; ms: number; error: string } and write a function that handles both branches.
Explain when a function should return void vs never. Give one example each from a Playwright test helper.
Use a literal type to restrict sortBy to 'az' | 'za' | 'lohi' | 'hilo' and watch the compiler reject typos.
Exercise answer key: discriminated union for test resultExercise answer key: void (returns) vs never (does not)Exercise answer key: literal union for sortBy
Chapter 19. Interfaces describe the shape of an object. They are the way a TTACart product, a login payload, or a checkout step talks to the rest of the framework.
Sub-topics covered
interface declarationoptional properties (?)readonly fieldsmethod signaturesextending interfacesimplements on a classindex signaturesinterface vs type aliasdeclaration merging
classDiagram
class UserBase {
+id: string
+email: string
}
class AdminUser {
+permissions: string[]
}
UserBase <|-- AdminUser
Interface extends - AdminUser inherits all UserBase fieldsOptional (?) and readonly modifiers in an interface
Exercises typical for this module
Convert a JS object literal that represents a TTACart product into an interface Product. Mark the description optional and the SKU readonly.
Extend interface UserBase with interface AdminUser that adds a permissions: string[] field. Show that a function accepting UserBase still accepts an AdminUser.
Write a class CheckoutStepOnePage implements ICheckoutPage and let the compiler tell you which methods are missing.
Use an index signature to type a dynamic env map: interface Env { [key: string]: string | undefined } and explain why undefined matters.
Pick: type vs interface for a union of 'desktop' | 'mobile'. Justify in two lines.
Exercise answer key: interface vs type aliasExercise answer key: index signature with | undefined
A small TTA-targeted interface - illustrative only, written fresh:
Single generic T - inference flows from argument to return
flowchart LR
F[pair<T, U>(t, u)] --> T[T from first arg]
F --> U[U from second arg]
T --> R[[t, u]: [T, U]]
U --> R
Multiple type params - T and U inferred independently
flowchart LR
S[T extends { id: string }] --> A[ok: { id, name }]
S --> B[ok: { id, email, age }]
S --> C[FAIL: { name } - no id]
S --> D[FAIL: number - no id]
Constraint <T extends X> - only types matching X allowed
Exercises typical for this module
Write a generic wrap<T>(value: T): { value: T } and test the inference - hover over the return type for three call sites.
Implement readJson<T>(path: string): Promise<T>, then call it with an explicit type argument readJson<User[]>('users.json').
Add a constraint: function getId<T extends { id: string }>(x: T) and prove the compiler now rejects objects without id.
Use Partial<Product> to type a patch-update helper. Add a Required<Product, 'sku'> variant.
Write a generic Page Object base: class BasePage<L extends Locators> where L describes the locator dictionary.
Generic Page Object - flow
flowchart LR
A[BasePage<L>] --> B[LoginPage with L = LoginLocators]
A --> C[InventoryPage with L = InvLocators]
A --> D[CartPage with L = CartLocators]
B --> E[expect on this.locators.user]
C --> F[click on this.locators.sortSelect]
D --> G[count on this.locators.cartItems]
Exercise answer key: generic identity inference tableExercise answer key: Partial maps every field to optionalExercise answer key: explicit type arg for readJson
Chapter 22. The final piece. public, private, protected, readonly, parameter properties, abstract classes - the syntax that ties Page Object Model + fixtures together.
Sub-topics covered
public (default)private vs #privateprotectedreadonly fieldsParameter propertiesabstract class + methodstatic membersgetters / settersimplements + extends