Skip to content

[Bug]: workers field in PlaywrightTestConfig breaks with exactOptionalPropertyTypes: true #35724

@kevin-m0

Description

@kevin-m0

Version

1.52.0

Steps to reproduce

  1. Clone this minimal repo minimal-reproduction
  2. Run 'npm install'
  3. Open playwright.config.ts
  4. Observe the TS error in the line:
    workers: process.env.CI ? 1 : undefined
  5. Remove "exactOptionalPropertyTypes": true from tsconfig.json and the error disappears

Expected behavior

This should be valid workers: process.env.CI ? 1 : undefined
Because workers is optional, assigning undefined should be fine under typical TypeScript behavior.

Actual behavior

TypeScript throws the following error:

Type 'number | undefined' is not assignable to type 'string | number'.
  Type 'undefined' is not assignable to type 'string | number'.ts(2769)

This only happens when exactOptionalPropertyTypes: true is enabled.

Additional context

  • This issue stems from the exactOptionalPropertyTypes flag introduced in TypeScript 4.4, which enforces stricter typing around optional fields.

  • Playwright's current typings assume the looser default behavior (optional? implicitly allows undefined), which breaks in stricter TS configs.

  • This type of issue can silently discourage teams from enabling stricter type checking, which is increasingly standard in modern TypeScript codebases.

  • Other config fields may also be affected — it’s worth auditing all optional fields for compatibility with exactOptionalPropertyTypes.

Environment

System:
    OS: Linux 6.11 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
    CPU: (16) x64 12th Gen Intel(R) Core(TM) i5-12500H
    Memory: 5.12 GB / 15.32 GB
    Container: Yes
  Binaries:
    Node: 22.14.0 - ~/.nvm/versions/node/v22.14.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v22.14.0/bin/npm
    pnpm: 10.4.0 - ~/.nvm/versions/node/v22.14.0/bin/pnpm
  Languages:
    Bash: 5.2.21 - /usr/bin/bash
  npmPackages:
    @playwright/test: ^1.52.0 => 1.52.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions