client triggerBrowser typization improvement
This commit is contained in:
parent
a0e8c0b461
commit
c94bab24f2
@ -15,6 +15,7 @@ import {
|
|||||||
RageFW_CefEvent,
|
RageFW_CefEvent,
|
||||||
RageFW_CefArgs,
|
RageFW_CefArgs,
|
||||||
RageFW_CefReturn,
|
RageFW_CefReturn,
|
||||||
|
_CefEventHasArgs,
|
||||||
} from './types'
|
} from './types'
|
||||||
|
|
||||||
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
import type { RageFW_ICustomClientEvent } from 'rage-fw-shared-types'
|
||||||
@ -59,7 +60,9 @@ class Player {
|
|||||||
|
|
||||||
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
public triggerBrowser<EventName extends RageFW_CefEvent>(
|
||||||
eventName: EventName,
|
eventName: EventName,
|
||||||
args: RageFW_CefArgs<EventName>,
|
...args: _CefEventHasArgs<EventName> extends true
|
||||||
|
? [RageFW_CefArgs<EventName>]
|
||||||
|
: []
|
||||||
): Promise<RageFW_CefReturn<EventName>> {
|
): Promise<RageFW_CefReturn<EventName>> {
|
||||||
if (!this.browser)
|
if (!this.browser)
|
||||||
throw new Error('You need to initialize browser first!')
|
throw new Error('You need to initialize browser first!')
|
||||||
|
@ -11,3 +11,10 @@ export type RageFW_CefArgs<K extends RageFW_CefEvent> = Parameters<
|
|||||||
export type RageFW_CefReturn<K extends RageFW_CefEvent> = ReturnType<
|
export type RageFW_CefReturn<K extends RageFW_CefEvent> = ReturnType<
|
||||||
RageFW_ICustomCefEvent[K]
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user