FiveM RPC Shared Types
Event and command declarations for @entityseven/fivem-rpc. With nothing declared, every rpc method accepts any event name, any arguments and any result. Declare your events once and every on* and emit* call gets checked names, arguments and results
Installation
See the main readme. The declaration file below imports this package, so it must resolve from that file (in a workspace: install it in the root)
Usage
-
Create one declaration file shared by server, client and webview code, e.g.
shared/rpc.d.ts:import '@entityseven/fivem-rpc-shared-types' declare module '@entityseven/fivem-rpc-shared-types' { interface RPCEvents_ClientServer { // event name(arguments): value returned by the listener buyItem(item: string, amount: number): boolean } interface RPCCommands_Server { ban: true } }The
importline makes the file a module, sodeclare moduleadds to the package's interfaces instead of replacing them -
Add the file to
includein thetsconfig.jsonof every environment:{ "include": ["src", "../shared/rpc.d.ts"] } -
Calls are checked from now on:
// server rpc.onClient('buyItem', (player, item, amount) => { // item: string, amount: number, must return boolean return true }) // client const bought = await rpc.emitServer('buyItem', 'water', 2) // boolean await rpc.emitServer('buyItem', 'water') // error: missing `amount` await rpc.emitServer('buyItme', 'water', 2) // error: unknown event
Interfaces
Each interface types one direction, see the direction table for which emit* and on* methods use it. RPCCommands_Server and RPCCommands_Client type onCommand. An interface you leave empty stays loose (any name, arguments and result), so you can declare them one at a time
- events: the member name is the event name, its parameters are the arguments, its return type is what
emit*resolves with. ServeronClientandonWebviewlisteners get the player id before the declared arguments. Names that are not identifiers work too:'buy-item'(item: string): boolean - commands: the key is the command name, the value is not used (
true)
License
Licensed under the Custom Attribution-NoDerivs Software License