Sparround

TypeScript essentials

TypeScript = JavaScript + static types. It catches mistakes before the code runs and powers editor autocomplete — making refactoring safe in large test bases. It's the de-facto standard for Playwright projects.

Core constructs:

  • Type annotations: const retries: number = 3, function login(user: string): Promise<void>
  • interface/type — describe object shapes: test data, API responses
  • Union types: type Env = 'dev' | 'stage' | 'prod' — only these three values allowed (a typo'd env name fails compilation!)
  • Optional fields: middleName?: string
  • Generics (the core idea): ApiResponse<User> — same structure, different inner type

The any type switches TypeScript off — any everywhere means not using TS at all. For unknown data use unknown: it forces a type check before use. Be ready for the "why do you avoid any?" interview question.

📚 Sources and documentation