Skip to content

[Bug]: ConsoleMessage type is kind of inadequate #36036

Open
@kaiyoma

Description

@kaiyoma

Version

1.49.0

Steps to reproduce

    page.on('console', (consoleMessage) => {
      if (consoleMessage.type() === 'warn') {

Expected behavior

The code above should throw a TypeScript error.

Actual behavior

The code above does not throw a TypeScript error.

Additional context

I see this in the Playwright types:

  /**
   * One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`,
   * `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`,
   * `'profileEnd'`, `'count'`, `'timeEnd'`.
   */
  type(): string;

This is silly. Instead of putting those values into a comment, make that the actual (union) type, so that everyone gets the benefit of stricter types. Because we've been incorrectly looking for "warn" (instead of "warning") in our code, we've been missing test failures for a while now.

Environment

System:
    OS: Windows 11 10.0.26100
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz
    Memory: 2.81 GB / 15.71 GB
  Binaries:
    Node: 22.14.0 - C:\Program Files\Node.js\node.EXE
    npm: 11.1.0 - C:\Program Files\Node.js\npm.CMD
  IDEs:
    VSCode: 1.100.2 - C:\Users\kgetz\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD
  Languages:
    Bash: 5.2.26 - C:\Users\kgetz\AppData\Local\Programs\Git\usr\bin\bash.EXE

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions