Invocable
An Invocable represents a callable entity, which can be either:
- A function
InvocableFn - An object with a specific invocation signature (
IInvocableObject)
Types
Invocable- Union type ofInvocableFnandIInvocableObjectInvocableFn- Function signatureIInvocableObject- Object withinvokemethod
Function Invocable (InvocableFn)
Represents a standard function with typed parameters and return value.
import type { InvocableFn } from "eridu-tech/utilities";
// Using InvocableFn
type AddFunction = InvocableFn<[arg1: number, arg2: number], number>;
// Equivalent to:
type TraditionalFunction = (arg1: number, arg2: number) => number;
Object Invocable (IInvocableObject)
An object that implements a callable contract through an invoke method. This pattern is especially useful for dependency injection (DI) integration, as most DI frameworks are adapted for class-based resolution.
import type { IInvocableObject } from "eridu-tech/utilities";
class InvocableObject implements IInvocableObject<
[arg1: number, arg2: number],
number
> {
invoke(arg1: number, arg2: number): number {
throw new Error("Method not implemented.");
}
}
const invocableObject: IInvocableObject<[arg1: number, arg2: number], number> =
{
invoke(arg1: number, arg2: number): number {
throw new Error("Method not implemented.");
},
};
Further information
For further information refer to eridu-tech/utilities API docs.