-
Notifications
You must be signed in to change notification settings - Fork 17
refactor: wrap up rewrite in TS #39
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
Changes from all commits
524d44b
1369415
25a33c2
e78c549
a68ed72
0698857
be165d4
594c11d
3fd7fbc
aca222b
aae7290
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| import type { PlaywrightPlugin, PuppeteerPlugin } from '.'; | ||
| import type { BrowserPlugin } from './abstract-classes/browser-plugin'; | ||
|
|
||
| export function addTimeoutToPromise<T>(promise: Promise<T>, timeoutMillis: number, errorMessage: string): Promise<T> { | ||
| return new Promise(async (resolve, reject) => { // eslint-disable-line | ||
| const timeout = setTimeout(() => reject(new Error(errorMessage)), timeoutMillis); | ||
|
|
@@ -16,3 +19,36 @@ export type UnwrapPromise<T> = T extends PromiseLike<infer R> ? UnwrapPromise<R> | |
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars | ||
| export function noop(..._args: unknown[]): void {} | ||
|
|
||
| export type InferBrowserPluginArray< | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is considered art 🤩
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That... I don't know, I've never actually measured that before 😓
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That shouldn't have a significant impact imo. Many other packages do unwrapping as well. |
||
| // The original array input | ||
| Input extends readonly unknown[], | ||
| // The results of this type | ||
| Result extends BrowserPlugin[] = [] | ||
| > = | ||
| // If the input is a tuple or a readonly array (`[] as const`), get the first and the rest of the values | ||
| Input extends readonly [infer FirstValue, ...infer Rest] | [infer FirstValue, ...infer Rest] | ||
| // If the first value is a PlaywrightPlugin | ||
| ? FirstValue extends PlaywrightPlugin | ||
| // Add it to the result, and continue parsing | ||
| ? InferBrowserPluginArray<Rest, [...Result, PlaywrightPlugin]> | ||
| // Else if the first value is a PuppeteerPlugin | ||
| : FirstValue extends PuppeteerPlugin | ||
| // Add it to the result, and continue parsing | ||
| ? InferBrowserPluginArray<Rest, [...Result, PuppeteerPlugin]> | ||
| // Return never as it isn't a valid type | ||
| : never | ||
| // If there's no more inputs to parse | ||
| : Input extends [] | ||
| // Return the results | ||
| ? Result | ||
| // If the input is a general array of elements (not a tuple), infer it's values type | ||
| : Input extends Array<infer U> | ||
| // If the values are a union of the plugins | ||
| ? [U] extends [PuppeteerPlugin | PlaywrightPlugin] | ||
| // Return an array of the union | ||
| ? U[] | ||
| // Return never as it isn't a valid type | ||
| : never | ||
| // Return the result | ||
| : Result; | ||
Uh oh!
There was an error while loading. Please reload this page.