Skip to content

chore: upgrade internal types to support TypeScript 4.9.3 #19280

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

Merged
merged 3 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"@babel/preset-react": "^7.18.6",
"@types/codemirror": "^5.60.5",
"@types/formidable": "^2.0.4",
"@types/node": "=14.18.24",
"@types/node": "=14.18.34",
"@types/react": "^18.0.12",
"@types/react-dom": "^18.0.5",
"@types/resize-observer-browser": "^0.1.7",
Expand Down Expand Up @@ -94,7 +94,7 @@
"rimraf": "^3.0.2",
"socksv5": "0.0.6",
"ssim.js": "^3.5.0",
"typescript": "^4.7.3",
"typescript": "^4.9.3",
"vite": "^3.2.1",
"ws": "^8.5.0",
"xml2js": "^0.4.23",
Expand Down
1 change: 1 addition & 0 deletions packages/playwright-core/src/server/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
}

export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
__elementhandle: T = true as any;
declare readonly _context: FrameExecutionContext;
readonly _page: Page;
declare readonly _objectId: string;
Expand Down
13 changes: 10 additions & 3 deletions packages/playwright-core/src/server/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ export type RemoteObject = {
value?: any
};

type NoHandles<Arg> = Arg extends JSHandle ? never : (Arg extends object ? { [Key in keyof Arg]: NoHandles<Arg[Key]> } : Arg);
interface TaggedAsJSHandle<T> {
__jshandle: T;
}
interface TaggedAsElementHandle<T> {
__elementhandle: T;
}
type NoHandles<Arg> = Arg extends TaggedAsJSHandle<any> ? never : (Arg extends object ? { [Key in keyof Arg]: NoHandles<Arg[Key]> } : Arg);
type Unboxed<Arg> =
Arg extends dom.ElementHandle<infer T> ? T :
Arg extends JSHandle<infer T> ? T :
Arg extends TaggedAsElementHandle<infer T> ? T :
Arg extends TaggedAsJSHandle<infer T> ? T :
Arg extends NoHandles<Arg> ? Arg :
Arg extends [infer A0] ? [Unboxed<A0>] :
Arg extends [infer A0, infer A1] ? [Unboxed<A0>, Unboxed<A1>] :
Expand Down Expand Up @@ -129,6 +135,7 @@ export class ExecutionContext extends SdkObject {
}

export class JSHandle<T = any> extends SdkObject {
__jshandle: T = true as any;
readonly _context: ExecutionContext;
_disposed = false;
readonly _objectId: ObjectId | undefined;
Expand Down
2 changes: 1 addition & 1 deletion tests/config/queryObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function queryObjectCount(type: Function): Promise<number> {
prototypeObjectId: constructorFunction.objectId
}, (_, result) => f(result))) as any;

const { result: { value } } = await new Promise(f => session.post('Runtime.callFunctionOn', {
const { result: { value } } = await new Promise<any>(f => session.post('Runtime.callFunctionOn', {
functionDeclaration: 'function (arr) { return this.length; }',
objectId: instanceArray.objectId,
arguments: [{ objectId: instanceArray.objectId }],
Expand Down
3 changes: 1 addition & 2 deletions tests/page/page-keyboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,7 @@ async function captureLastKeydown(page) {
lastEvent.key = e.key;
lastEvent.code = e.code;
lastEvent.metaKey = e.metaKey;
// keyIdentifier only exists in WebKit, and isn't in TypeScript's lib.
lastEvent.keyIdentifier = 'keyIdentifier' in e && e['keyIdentifier'];
lastEvent.keyIdentifier = 'keyIdentifier' in e && typeof e['keyIdentifier'] === 'string' && e['keyIdentifier'];
}, true);
return lastEvent;
});
Expand Down
18 changes: 18 additions & 0 deletions utils/generate_types/test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,23 @@ playwright.chromium.launch().then(async browser => {
const value = await handle.jsonValue();
const assertion: AssertType<number, typeof value> = true;
}
{
const handle = await page.evaluateHandle(() => document.body);
const tuple = { s: '', n: 23, h: handle };
const value = await page.evaluate(([{ s, n, h }]) => {
return parseInt(s) + n + parseInt(h.nodeName);
}, [tuple]);
const assertion: AssertType<number, typeof value> = true;
}
{
type T = ({ s: string } | playwright.ElementHandle)[];
const handle = await page.evaluateHandle(() => document.body);
const tuple: T = [{ s: '' }, handle];
const value = await page.evaluate(([a, b]) => {
return (a instanceof Node ? a.nodeName : a.s) + (b instanceof Node ? b.nodeName : b.s);
}, tuple);
const assertion: AssertType<string, typeof value> = true;
}

{
const handle = await page.evaluateHandle(() => document.createElement('body'));
Expand Down Expand Up @@ -861,3 +878,4 @@ import {
Geolocation,
HTTPCredentials,
} from 'playwright';