diff --git a/client/index.d.ts b/client/index.d.ts index 13dda85b..ef77e474 100644 --- a/client/index.d.ts +++ b/client/index.d.ts @@ -2554,7 +2554,8 @@ declare module "alt-client" { * @remarks Exceptions will be thrown when there was an error on server-side. * */ - export function emitRpc(rpcName: string, ...args: unknown[]): Promise; + export function emitRpc(rpcName: K, ...args: Parameters): Promise>; + export function emitRpc(rpcName: Exclude, ...args: any[]): Promise; /** * Subscribes to a client event with the specified listener. @@ -2564,7 +2565,8 @@ declare module "alt-client" { * @remarks The return value of the listener function determines the response clients will receive. When returning multiple values, use an array. Returning an Error object will cause the promise on the server to throw an exception which has to be caught. * */ - export function onRpc(rpcName: string, listener: (...args: unknown[]) => Promise | unknown): void; + export function onRpc(rpcName: K, listener: (...args: Parameters) => Promise | ReturnType): void; + export function onRpc(rpcName: Exclude, listener: (...args: any[]) => Promise | any): void; /** * @@ -2572,7 +2574,8 @@ declare module "alt-client" { * @param listener Listener that should be added. * */ - export function offRpc(rpcName: string, listener?: (player: Player, ...args: unknown[]) => Promise | unknown): void; + export function offRpc(rpcName: K, listener?: (...args: Parameters) => Promise> | ReturnType): void; + export function offRpc(rpcName: Exclude, listener?: (...args: any[]) => Promise | any): void; /** * Returns whether the game controls are currently enabled. diff --git a/server/index.d.ts b/server/index.d.ts index e1e90634..611993db 100644 --- a/server/index.d.ts +++ b/server/index.d.ts @@ -1118,7 +1118,8 @@ declare module "alt-server" { * @param ...args Arguments to pass to the RPC * */ - public emitRpc(rpcName: string, ...args: unknown[]): Promise; + public emitRpc(rpcName: K, ...args: Parameters): Promise>; + public emitRpc(rpcName: Exclude, ...args: any[]): Promise; public addWeaponComponent(weaponHash: number, component: number): void; @@ -2990,7 +2991,8 @@ declare module "alt-server" { * @remarks The return value of the listener function determines the response clients will receive. When returning multiple values, use an array. Returning an Error object will cause the promise on the client to throw an exception which has to be caught. * */ - export function onRpc(rpcName: string, listener: (player: Player, ...args: unknown[]) => Promise | unknown): void; + export function onRpc(rpcName: K, listener: (player: Player, ...args: Parameters) => Promise> | ReturnType): void; + export function onRpc(rpcName: Exclude, listener: (player: Player, ...args: any[]) => Promise | any): void; /** * @@ -2998,7 +3000,8 @@ declare module "alt-server" { * @param listener Listener that should be added. * */ - export function offRpc(rpcName: string, listener?: (player: Player, ...args: unknown[]) => Promise | unknown): void; + export function offRpc(rpcName: string, listener: (player: Player, ...args: Parameters) => Promise> | ReturnType): void; + export function offRpc(rpcName: Exclude, listener?: (player: Player, ...args: any[]) => Promise | any): void; /** * Change the server password at runtime. diff --git a/shared/index.d.ts b/shared/index.d.ts index dec9fa3c..7e979f7d 100644 --- a/shared/index.d.ts +++ b/shared/index.d.ts @@ -1929,6 +1929,40 @@ declare module "alt-shared" { */ export interface ICustomClientServerEvent {} + /** + * Extend `player.emitRpc` and `alt.onRpc` auto-completion by merging interfaces. + * + * @example + * ```ts + * declare module 'alt-client' { + * interface ICustomServerClientRpc { + * myRpc: (arg1: string, arg2: { key: string, value: number }): Promise + * } + * } + * ``` + * + * @export + * @interface ICustomServerClientRpc + */ + export interface ICustomServerClientRpc {} + + /** + * Extend `alt.onRpc` and `alt.emitRpc` auto-completion by merging interfaces. + * + * @example + * ```ts + * declare module 'alt-client' { + * interface ICustomClientServerRpc { + * myRpc: (arg1: string, arg2: { key: string, value: number }): Promise + * } + * } + * ``` + * + * @export + * @interface ICustomClientServerRpc + */ + export interface ICustomClientServerRpc {} + export interface IInspectOptions { /** * If set to `true`, getters are going to be