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 23 of 60~12 min • Beginner
Chapter 23TypeScript

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

  1. Declare typed variables
  2. Use inference
  3. Run the compiler

Example

TypeScript
const browser: string = 'chromium';
const retries = 2;
function label(name: string): string {
  return `Browser: ${name}`;
}
console.log(label(browser), retries);
Expected result: Browser: chromium 2
💡 Point to remember
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