server triggerBrowser typization improvement

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

View File

@ -6,6 +6,7 @@ import {
RageFW_CefArgs,
RageFW_CefEvent,
RageFW_CefReturn,
_CefEventHasArgs,
_ClientEventHasArgs,
_ServerEventHasArgs,
RageFW_ClientEvent,
@ -128,7 +129,9 @@ class Player {
public triggerBrowser<EventName extends RageFW_CefEvent>(
player: PlayerMp,
eventName: EventName,
args: RageFW_CefArgs<EventName>,
...args: _CefEventHasArgs<EventName> extends true
? [RageFW_CefArgs<EventName>]
: []
): Promise<RageFW_CefReturn<EventName>> {
return rpc.callBrowsers(player, eventName, args)
}

View File

@ -9,3 +9,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