Skip to content

Commit

Permalink
fix: remove internal func typings from overwriteCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
KuznetsovRoman committed Mar 26, 2024
1 parent 3d131b8 commit ef75066
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/browser/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { EventEmitter } from "events";
import type { AssertViewCommand, AssertViewElementCommand } from "./commands/types";
import type { BrowserConfig } from "./../config/browser-config";
import type { AssertViewResult, RunnerTest, RunnerHook } from "../types";
Expand All @@ -17,15 +18,22 @@ export interface Browser {
applyState: (state: Record<string, unknown>) => void;
}

type FunctionProperties<T> = keyof T &
type FunctionProperties<T> = Exclude<
{
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
}[keyof T];
}[keyof T],
undefined
>;

type EventEmitterMethod = FunctionProperties<EventEmitter>;

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace WebdriverIO {
type BrowserCommand = Exclude<FunctionProperties<WebdriverIO.Browser>, EventEmitterMethod>;
type ElementCommand = Exclude<FunctionProperties<WebdriverIO.Element>, EventEmitterMethod>;

interface Browser {
getMeta(this: WebdriverIO.Browser): Promise<BrowserMeta>;
getMeta(this: WebdriverIO.Browser, key: string): Promise<unknown>;
Expand All @@ -36,15 +44,15 @@ declare global {

getConfig(this: WebdriverIO.Browser): Promise<BrowserConfig>;

overwriteCommand<CommandName extends FunctionProperties<WebdriverIO.Browser>>(
overwriteCommand<CommandName extends BrowserCommand>(
name: CommandName,
func: WebdriverIO.Browser[CommandName],
attachToElement?: false,
proto?: Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any
instances?: Record<string, WebdriverIO.Browser | WebdriverIO.MultiRemoteBrowser>,
): void;

overwriteCommand<CommandName extends FunctionProperties<WebdriverIO.Element>>(
overwriteCommand<CommandName extends ElementCommand>(
name: CommandName,
func: WebdriverIO.Element[CommandName],
attachToElement: true,
Expand Down

0 comments on commit ef75066

Please sign in to comment.