Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Getgauge Taiko Type Safety

From Leeroopedia
Revision as of 17:37, 16 February 2026 by Admin (talk | contribs) (Auto-imported from principles/Getgauge_Taiko_Type_Safety.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:Principle

Overview

Type Safety is the principle of providing compile-time type information for Taiko's public API surface, enabling IDE autocompletion, parameter validation, and self-documenting function signatures through TypeScript declaration files.

Description

Type safety in Taiko is achieved by maintaining a comprehensive TypeScript declaration file (types/taiko/index.d.ts) that describes the complete public API surface. This file defines interfaces for all option objects (BrowserOptions, NavigationOptions, ClickOptions, WriteOptions, ScreenshotOptions, etc.), element wrapper types (ElementWrapper, TextBoxWrapper, DropDownWrapper, CheckBoxWrapper, etc.), intercept types (InterceptRequest, InterceptMockData), and function declarations for all 80+ exported API methods.

Key benefits:

  • Compile-time error detection — Incorrect argument types, missing required parameters, or invalid option shapes are caught before runtime
  • IDE autocompletion — Full IntelliSense support for all Taiko functions and their parameters in TypeScript and JavaScript editors
  • Self-documenting API — Type declarations serve as machine-readable API documentation with JSDoc links to official docs
  • Refactoring safety — Type-aware tooling can safely rename and restructure code that depends on the Taiko API

Usage

Type safety applies whenever developers consume the Taiko API in their test scripts:

  • TypeScript projects importing taiko automatically receive full type checking via the "types" field in package.json
  • JavaScript projects benefit from JSDoc-powered IntelliSense in editors like VS Code that read .d.ts files
  • The declarations cover browser actions, page actions, selectors, proximity selectors, dialog handlers, and configuration helpers

Theoretical Basis

Type safety in dynamically-typed JavaScript libraries is achieved through TypeScript ambient declarations:

Developer writes Taiko script (.ts or .js)
        |
        v
Editor / TypeScript compiler resolves types
from types/taiko/index.d.ts
        |
        v
Parameter shapes validated against interfaces
(BrowserOptions, NavigationOptions, etc.)
        |
        v
Function signatures checked for:
  - Required parameters present
  - Correct argument types
  - Valid option object shapes
  - Return type awareness
        |
        v
Errors surfaced at compile-time / in editor
before test execution

The declaration file requires TypeScript >= 3.5 and imports devtools-protocol for the Protocol.Network.Cookie type alias, ensuring type fidelity with the underlying Chrome DevTools Protocol types.

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment