Principle:Getgauge Taiko Type Safety
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
taikoautomatically receive full type checking via the"types"field inpackage.json - JavaScript projects benefit from JSDoc-powered IntelliSense in editors like VS Code that read
.d.tsfiles - 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.