a library to speed up the development of Fivem scripts and frameworks
fivem-ts - Documentation v0.7.5 • Docs
fivem-ts - Documentation v0.7.5 / Shared / ServerOnly
ServerOnly(
target
,propertyKey
,descriptor
):void
A decorator that ensures a method is only executed on the server side.
The @ServerOnly
decorator modifies the behavior of the decorated method to prevent its execution
on the client side. If the method is called on the client side, a warning is logged and the method is replaced
with an empty function to prevent any unintended behavior.
Note: This decorator intended to be used in environments where both server and client code can be executed, such as in frameworks that support both server-side and client-side execution
• target: unknown
The prototype of the class.
• propertyKey: string
The name of the method being decorated.
• descriptor: PropertyDescriptor
The property descriptor for the method.
void
class Example {
@ServerOnly
public serverMethod() {
console.log('This method should only run on the server side.');
}
}
const example = new Example();
example.serverMethod(); // Executes only if running on the server side.