client triggerBrowser typization improvement

This commit is contained in:
Oleksandr Honcharov 2024-06-13 04:51:13 +03:00
parent a0e8c0b461
commit c94bab24f2
2 changed files with 11 additions and 1 deletions

View File

@ -15,6 +15,7 @@ import {
RageFW_CefEvent,
RageFW_CefArgs,
RageFW_CefReturn,
_CefEventHasArgs,
} from './types'
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
@ -59,7 +60,9 @@ class Player {
public triggerBrowser<EventName extends RageFW_CefEvent>(
eventName: EventName,
args: RageFW_CefArgs<EventName>,
...args: _CefEventHasArgs<EventName> extends true
? [RageFW_CefArgs<EventName>]
: []
): Promise<RageFW_CefReturn<EventName>> {
if (!this.browser)
throw new Error('You need to initialize browser first!')

View File

@ -11,3 +11,10 @@ export type RageFW_CefArgs<K extends RageFW_CefEvent> = Parameters<
export type RageFW_CefReturn<K extends RageFW_CefEvent> = ReturnType<
RageFW_ICustomCefEvent[K]
>
export type _CefEventHasArgs<EventName extends keyof RageFW_ICustomCefEvent> =
keyof RageFW_ICustomCefEvent extends never
? false
: Parameters<RageFW_ICustomCefEvent[EventName]>[0] extends undefined
? false
: true