fix(types): fix type generation to make ts tests work (#3385)

This commit is contained in:
Joel Einbinder 2020-08-11 14:31:20 -07:00 committed by GitHub
parent 812d7eefe9
commit 55a78482e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -177,7 +177,7 @@ function classBody(classDesc) {
for (const {eventName, params, comment, type} of eventDescriptions) {
if (comment)
parts.push(writeComment(comment, ' '));
parts.push(` ${member.name}(event: '${eventName}', optionsOrPredicate?: { predicate?: (${params}) => boolean, timeout?: number }): Promise<${type}>;\n`);
parts.push(` ${member.name}(event: '${eventName}', optionsOrPredicate?: { predicate?: (${params}) => boolean, timeout?: number } | ((${params}) => boolean)): Promise<${type}>;\n`);
}
return parts.join('\n');
@ -232,6 +232,9 @@ function writeComment(comment, indent = '') {
function typeToString(type, ...namespace) {
if (!type)
return 'void';
// Accessibility.snapshot has a recursive data structure, so special case it here.
if (namespace[0] === 'AccessibilitySnapshot' && namespace[1] === 'children')
return 'Array<AccessibilitySnapshot>';
let typeString = stringifyType(parseType(type.name));
if (type.properties.length && typeString.indexOf('Object') !== -1) {
const name = namespace.map(n => n[0].toUpperCase() + n.substring(1)).join('');

View File

@ -399,6 +399,10 @@ playwright.chromium.launch().then(async browser => {
});
const assertion: AssertType<playwright.Page, typeof newPage> = true;
}
{
const response = await page.waitForEvent('response', response => response.url() === 'asdf');
const assertion: AssertType<playwright.Response, typeof response> = true;
}
})();
// typed handles