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!"