Skip to content

Commit

Permalink
Client|Shared|Server: Consisting typing for RPC
Browse files Browse the repository at this point in the history
  • Loading branch information
S0P4 authored Nov 5, 2023
1 parent 38bc5fa commit ad3530e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
9 changes: 6 additions & 3 deletions client/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2779,7 +2779,8 @@ declare module "alt-client" {
*
* @beta
*/
export function emitRpc(rpcName: string, ...args: unknown[]): Promise<unknown>;
export function emitRpc<K extends keyof shared.ICustomClientServerRpc>(rpcName: K, ...args: Parameters<shared.ICustomClientServerRpc[K]>): Promise<ReturnType<shared.ICustomClientServerRpc[K]>>;
export function emitRpc<K extends string>(rpcName: Exclude<K, keyof shared.ICustomClientServerRpc>, ...args: any[]): Promise<any>;

/**
* Subscribes to a client event with the specified listener.
Expand All @@ -2790,7 +2791,8 @@ declare module "alt-client" {
*
* @beta
*/
export function onRpc(rpcName: string, listener: (player: Player, ...args: unknown[]) => Promise<unknown> | unknown): void;
export function onRpc<K extends keyof shared.ICustomServerClientRpc>(rpcName: K, listener: (...args: Parameters<shared.ICustomServerClientRpc[K]>) => Promise<any> | ReturnType<any>): void;
export function onRpc<K extends string>(rpcName: Exclude<K, keyof shared.ICustomServerClientRpc>, listener: (...args: any[]) => Promise<any> | any): void;

/**
*
Expand All @@ -2799,7 +2801,8 @@ declare module "alt-client" {
*
* @beta
*/
export function offRpc(rpcName: string, listener?: (player: Player, ...args: unknown[]) => Promise<unknown> | unknown): void;
export function offRpc<K extends keyof shared.ICustomServerClientRpc>(rpcName: K, listener?: (...args: Parameters<shared.ICustomServerClientRpc[K]>) => Promise<ReturnType<shared.ICustomServerClientRpc[K]>> | ReturnType<shared.ICustomServerClientRpc[K]>): void;
export function offRpc<K extends string>(rpcName: Exclude<K, keyof shared.ICustomServerClientRpc>, listener?: (...args: any[]) => Promise<any> | any): void;

/**
* Returns whether the game controls are currently enabled.
Expand Down
11 changes: 7 additions & 4 deletions server/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,8 @@ declare module "alt-server" {
*
* @beta
*/
public emitRpc(rpcName: string, ...args: unknown[]): Promise<unknown>;
public emitRpc<K extends keyof shared.ICustomServerClientRpc>(rpcName: K, ...args: Parameters<shared.ICustomServerClientRpc[K]>): Promise<ReturnType<shared.ICustomServerClientRpc[K]>>;
public emitRpc<K extends string>(rpcName: Exclude<K, keyof shared.ICustomServerClientRpc>, ...args: any[]): Promise<any>;

public addWeaponComponent(weaponHash: number, component: number): void;

Expand Down Expand Up @@ -3145,16 +3146,18 @@ declare module "alt-server" {
*
* @beta
*/
export function onRpc(rpcName: string, listener: (player: Player, ...args: unknown[]) => Promise<unknown> | unknown): void;
export function onRpc<K extends keyof shared.ICustomClientServerRpc>(rpcName: K, listener: (player: Player, ...args: Parameters<shared.ICustomClientServerRpc[K]>) => Promise<ReturnType<shared.ICustomClientServerRpc[K]>> | ReturnType<shared.ICustomClientServerRpc[K]>): void;
export function onRpc<K extends string>(rpcName: Exclude<K, keyof shared.ICustomClientServerRpc>, listener: (player: Player, ...args: any[]) => Promise<any> | any): void;

/**
*
* @param rpcName Name of the RPC
* @param listener Listener that should be added.
*
* @beta
*/
export function offRpc(rpcName: string, listener?: (player: Player, ...args: unknown[]) => Promise<unknown> | unknown): void;
*/
export function offRpc<K extends keyof shared.ICustomClientServerRpc>(rpcName: string, listener: (player: Player, ...args: Parameters<shared.ICustomClientServerRpc[K]>) => Promise<ReturnType<shared.ICustomClientServerRpc[K]>> | ReturnType<shared.ICustomClientServerRpc[K]>): void;
export function offRpc<K extends string>(rpcName: Exclude<K, keyof shared.ICustomClientServerRpc>, listener?: (player: Player, ...args: any[]) => Promise<any> | any): void;

/**
* Change the server password at runtime.
Expand Down
34 changes: 34 additions & 0 deletions shared/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,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<boolean>
* }
* }
* ```
*
* @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<boolean>
* }
* }
* ```
*
* @export
* @interface ICustomClientServerRpc
*/
export interface ICustomClientServerRpc {}

export interface IInspectOptions {
/**
* If set to `true`, getters are going to be
Expand Down

0 comments on commit ad3530e

Please sign in to comment.