fix(types): allow any return type from event handlers (#30492)

Closes #29353.
This commit is contained in:
Dmitry Gozman 2024-04-24 09:25:43 -07:00 committed by GitHub
parent b1d963c24c
commit 8fc7723f22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 281 additions and 291 deletions

View File

@ -7,8 +7,6 @@ test/assets/modernizr.js
/packages/playwright-core/types/*
/packages/playwright-ct-core/src/generated/*
/index.d.ts
utils/generate_types/overrides.d.ts
utils/generate_types/test/test.ts
node_modules/
browser_patches/*/checkout/
browser_patches/chromium/output/

View File

@ -290,9 +290,7 @@ Emitted when a JavaScript dialog appears, such as `alert`, `prompt`, `confirm` o
**Usage**
```js
page.on('dialog', dialog => {
dialog.accept();
});
page.on('dialog', dialog => dialog.accept());
```
```java

File diff suppressed because it is too large Load Diff

View File

@ -43,9 +43,7 @@ it('should allow accepting prompts @smoke', async ({ page, isElectron }) => {
it('should dismiss the prompt', async ({ page, isElectron }) => {
it.skip(isElectron, 'prompt() is not a thing in electron');
page.on('dialog', dialog => {
void dialog.dismiss();
});
page.on('dialog', dialog => dialog.dismiss());
const result = await page.evaluate(() => prompt('question?'));
expect(result).toBe(null);
});

View File

@ -283,7 +283,7 @@ class TypesGenerator {
parts.push(this.writeComment(comment, indent));
else
parts.push(this.writeComment(commentForMethod[method], indent));
parts.push(` ${method}(event: '${eventName}', listener: (${params}) => void): this;\n`);
parts.push(` ${method}(event: '${eventName}', listener: (${params}) => any): this;\n`);
}
}

View File

@ -921,6 +921,10 @@ playwright.chromium.launch().then(async browser => {
.removeListener('close', listener)
.off('close', listener);
}
{
const page: playwright.Page = {} as any;
page.on('dialog', dialog => dialog.accept());
}
});
// waitForResponse callback predicate