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:Webdriverio Webdriverio Type System

From Leeroopedia
Knowledge Sources
Domains Type_Definitions, Architecture
Last Updated 2026-02-12 00:00 GMT

Overview

Defining a comprehensive static type system that models capabilities, configuration options, service interfaces, framework contracts, worker messages, and global runtime interfaces.

Description

A large-scale browser automation framework with a plugin ecosystem requires a rigorous type system to ensure correctness across package boundaries. The Type System principle defines TypeScript interfaces and types that model every major domain concept: browser capabilities (W3C standard and vendor-specific), configuration options (test runner, framework adapter, reporter, service), service lifecycle contracts (which methods a service must or may implement), framework adapter interfaces (how test runners like Mocha or Jasmine integrate), worker process message protocols (how the launcher and worker processes communicate), and global runtime interfaces (what properties are available on the global browser and $ objects). These types serve as the contract layer between independently developed packages, enabling compile-time verification that plugins conform to expected interfaces and that configuration objects contain valid properties.

Usage

This principle applies to any multi-package framework where independent modules must agree on shared interfaces. It is the right choice when the framework supports third-party plugins that must conform to specific contracts, when configuration objects are complex and deeply nested, and when inter-process communication requires message type safety. It enables IDE autocompletion, compile-time error detection, and self-documenting APIs across the entire framework ecosystem.

Theoretical Basis

The type system is organized around several key type-theoretic concepts:

  • Discriminated unions for message types: Worker-to-launcher messages and capability variants are modeled as tagged unions where a discriminant field determines the shape of the rest of the object:
type WorkerMessage =
    | { type: "spec:start", payload: { specPath: string } }
    | { type: "spec:done", payload: { passed: boolean, duration: number } }
    | { type: "error", payload: { message: string, stack: string } }
  • Intersection types for capability merging: Browser capabilities combine W3C standard fields with vendor-specific extensions using intersection types, ensuring that both standard and vendor fields are accessible:
type Capabilities = W3CCapabilities & VendorCapabilities & {
    "appium:options"?: AppiumCapabilities
    "goog:chromeOptions"?: ChromeOptions
}
  • Declaration merging for global augmentation: The global browser object's type is defined in a base package and augmented by plugins through TypeScript's declaration merging. Each service or plugin can add its own properties to the global interface without modifying the core type definitions:
// Core package declares base interface
interface Browser { $: (selector) => Element }
// Plugin augments it
interface Browser { customCommand: () => void }
  • Generic constraints for service contracts: Service interfaces use generics to express relationships between configuration types and runtime behavior:
interface ServiceClass<T extends ServiceOptions> {
    new(options: T, capabilities: Capabilities): ServiceInstance
}
  • Mapped types for configuration validation: Configuration objects use mapped types to derive option types from default values, ensuring that user-provided overrides match the expected types:
type ConfigOverrides<T> = { [K in keyof T]?: T[K] }

The type system serves as a living specification -- changes to interfaces are immediately surfaced as compile errors across all dependent packages, enforcing consistency throughout the monorepo.

Related Pages

Page Connections

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