From 82aefd24db1ba9977c3f6953347ee266845790ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Wed, 17 Apr 2024 02:39:11 +0200 Subject: [PATCH] types: allow readonly tuples to be used as `ReporterDescription` (#30387) This makes it easier to create helper functions like: ```ts function createReporter(options: MyOptions) { return ['my-reporter', options] as const } ``` At the moment, such functions can't be passed to `reporters` because a readonly array is not assignable to the expected mutable array. Playwirght certainly doesn't require those arrays to be mutable so it would make sense to relax this. --- packages/playwright/types/test.d.ts | 5 +++-- utils/generate_types/overrides-test.d.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index fe74d00184..42d85d45fc 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -18,7 +18,7 @@ import type { APIRequestContext, Browser, BrowserContext, BrowserContextOptions, Page, LaunchOptions, ViewportSize, Geolocation, HTTPCredentials, Locator, APIResponse, PageScreenshotOptions } from 'playwright-core'; export * from 'playwright-core'; -export type ReporterDescription = +export type ReporterDescription = Readonly< ['blob'] | ['blob', { outputDir?: string, fileName?: string }] | ['dot'] | ['line'] | @@ -28,7 +28,8 @@ export type ReporterDescription = ['json'] | ['json', { outputFile?: string }] | ['html'] | ['html', { outputFolder?: string, open?: 'always' | 'never' | 'on-failure', host?: string, port?: number, attachmentsBaseURL?: string }] | ['null'] | - [string] | [string, any]; + [string] | [string, any] +>; type UseOptions = Partial & Partial; diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts index 72cdf3a7b3..9d58db13fe 100644 --- a/utils/generate_types/overrides-test.d.ts +++ b/utils/generate_types/overrides-test.d.ts @@ -17,7 +17,7 @@ import type { APIRequestContext, Browser, BrowserContext, BrowserContextOptions, Page, LaunchOptions, ViewportSize, Geolocation, HTTPCredentials, Locator, APIResponse, PageScreenshotOptions } from 'playwright-core'; export * from 'playwright-core'; -export type ReporterDescription = +export type ReporterDescription = Readonly< ['blob'] | ['blob', { outputDir?: string, fileName?: string }] | ['dot'] | ['line'] | @@ -27,7 +27,8 @@ export type ReporterDescription = ['json'] | ['json', { outputFile?: string }] | ['html'] | ['html', { outputFolder?: string, open?: 'always' | 'never' | 'on-failure', host?: string, port?: number, attachmentsBaseURL?: string }] | ['null'] | - [string] | [string, any]; + [string] | [string, any] +>; type UseOptions = Partial & Partial;