Skip to content
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

exporting Devices type #30223

Closed
wants to merge 1 commit into from
Closed

exporting Devices type #30223

wants to merge 1 commit into from

Conversation

AlfieJones
Copy link

@AlfieJones AlfieJones commented Apr 3, 2024

This pr exports the auto-generated Devices type.

Without exporting, you can only access the more generic version with type Devices = typeof devices which results in the type [key: string]: DeviceDescriptor which doesn't have the 'autocompleted' keys

Signed-off-by: Alfie Jones <alfie.jones@hotmail.co.uk>
Copy link
Contributor

github-actions bot commented Apr 3, 2024

Test results for "tests 1"

6 flaky ⚠️ [chromium-library] › library/tracing.spec.ts:243:5 › should not include trace resources from the previous chunks
⚠️ [firefox-library] › library/tracing.spec.ts:243:5 › should not include trace resources from the previous chunks
⚠️ [firefox-page] › page/page-click-timeout-4.spec.ts:20:3 › should timeout waiting for stable position
⚠️ [firefox-page] › page/page-event-request.spec.ts:171:3 › should return response body when Cross-Origin-Opener-Policy is set
⚠️ [playwright-test] › ui-mode-trace.spec.ts:76:5 › should merge screenshot assertions
⚠️ [chromium-library] › library/tracing.spec.ts:243:5 › should not include trace resources from the previous chunks

26903 passed, 618 skipped
✔️✔️✔️

Merge workflow run.

@dgozman
Copy link
Contributor

dgozman commented Apr 4, 2024

@AlfieJones The following snippet correctly identifies that instance.viewport is missing width/height, so I'd think that typeof devices works nicely.

import { devices } from '@playwright/test';
type Devices = typeof devices;
type iPhone = Devices['iPhone X'];
const instance: iPhone = { viewport: {} };

@AlfieJones
Copy link
Author

The issue for me is replicating the autocomplete experience devices offers. When using the object directly, typescript is able to show be the available devices. However when using the derived type, I am not able to replicate the functionality.

import { devices } from 'playwright-core';

// lsp shows the available options
const iPhone = devices['iPhone X'];

type Devices = typeof devices;
const example = {} as Devices;

// lsp doesn't show available options
const iPhone = example ['iPhone X'];

@AlfieJones
Copy link
Author

In my project, https://github.com/pixeleye-io/pixeleye, I'm re-exporting this object of devices after adding additional properties to each of the elements. If possible, I'd rather avoid recreating a similar custom-type generator as you've implemented.

@yury-s
Copy link
Member

yury-s commented Apr 15, 2024

How exactly do you export modified devices? The following code works fine:

// helper.ts
import { devices } from 'playwright-core';

type Devices = typeof devices;
export const example: Devices = {} as Devices;
image

@dgozman
Copy link
Contributor

dgozman commented May 1, 2024

Closing since the issue is not reproducible. Next time, could you please start with filing an issue instead of sending a PR right away?

@dgozman dgozman closed this May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants