before()
before<
In,Out>(hook):Decorator<In,Out>
Creates a decorator that runs a hook before the function executes.
Type Parameters
In: In
The input type
Out: Out
The output type
Parameters
hook: (input) => void
Function to run before, receives the input
Returns: Decorator<In, Out>
A Decorator
Since
2.4.0
Example
const withLog = before<string, string>((name) => {
console.log(`calling greet with: ${name}`);
});
const greet = withLog((name) => `Hello, ${name}!`);
greet("Alice"); // logs then returns "Hello, Alice!"