Skip to content

fix(types): update ConsoleMessage.type() to return specific string literals #36050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
2 changes: 1 addition & 1 deletion docs/src/api/class-consolemessage.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ The text of the console message.

## method: ConsoleMessage.type
* since: v1.8
- returns: <[string]>
- returns: <[string]<"log"|"debug"|"info"|"error"|"warning"|"dir"|"dirxml"|"table"|"trace"|"clear"|"startGroup"|"startGroupCollapsed"|"endGroup"|"assert"|"profile"|"profileEnd"|"count"|"timeEnd">>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to duplicate the definition of the method to keep different signature for js and other languages: one definition should have * langs: js and the other with return type string, should be * langs: csharp, java, python. Also the enum name should be [ConsoleMessageType] not [string].

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the documentation with separate method definitions for different languages. The JS version now returns [ConsoleMessageType] while the csharp, java, and python versions return [string]. Commit: 569e3d0


One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`,
`'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, `'profileEnd'`,
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-client/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18838,7 +18838,7 @@ export interface ConsoleMessage {
* `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`,
* `'profileEnd'`, `'count'`, `'timeEnd'`.
*/
type(): string;
type(): "log"|"debug"|"info"|"error"|"warning"|"dir"|"dirxml"|"table"|"trace"|"clear"|"startGroup"|"startGroupCollapsed"|"endGroup"|"assert"|"profile"|"profileEnd"|"count"|"timeEnd";
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/playwright-core/src/client/consoleMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export class ConsoleMessage implements api.ConsoleMessage {
return this._page;
}

type(): string {
return this._event.type;
type(): 'log'|'debug'|'info'|'error'|'warning'|'dir'|'dirxml'|'table'|'trace'|'clear'|'startGroup'|'startGroupCollapsed'|'endGroup'|'assert'|'profile'|'profileEnd'|'count'|'timeEnd' {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reference the return type from the public API, instead of repeating it ReturnType<ConsoleMessage["type"]> ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the implementation to reference the return type from the public API using ReturnType<api.ConsoleMessage["type"]> instead of repeating the union type. Commit: 569e3d0

return this._event.type as 'log'|'debug'|'info'|'error'|'warning'|'dir'|'dirxml'|'table'|'trace'|'clear'|'startGroup'|'startGroupCollapsed'|'endGroup'|'assert'|'profile'|'profileEnd'|'count'|'timeEnd';
}

text(): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18838,7 +18838,7 @@ export interface ConsoleMessage {
* `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`,
* `'profileEnd'`, `'count'`, `'timeEnd'`.
*/
type(): string;
type(): "log"|"debug"|"info"|"error"|"warning"|"dir"|"dirxml"|"table"|"trace"|"clear"|"startGroup"|"startGroupCollapsed"|"endGroup"|"assert"|"profile"|"profileEnd"|"count"|"timeEnd";
}

/**
Expand Down