Chapter 23: Type annotations and inference
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Type annotations and inference
Type annotations describe expected value types. TypeScript infers many types from initializers, so annotations are not required everywhere. Function parameter annotations help document and check contracts.
How it works
Step-by-step walkthrough
- Declare typed variables
- Use inference
- Run the compiler
Example
const browser: string = 'chromium';
const retries = 2;
function label(name: string): string {
return `Browser: ${name}`;
}
console.log(label(browser), retries);Prefer inference for obvious local values.
✎ Your practice task
Pass a number to label and inspect the error.
Knowledge check
What type is inferred for let retries = 2?
🌐 Continue learning
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.