Invokable
An Invokable represents a callable entity, which can be either:
- A function
InvokableFn - An object with a specific invocation signature (
IInvokableObject)
Types
Invokable- Union type ofInvokableFnandIInvokableObjectInvokableFn- Function signatureIInvokableObject- Object withinvokemethod
Function Invokable (InvokableFn)
Represents a standard function with typed parameters and return value.
import type { InvokableFn } from "@daiso-tech/core/utilities";
// Using InvokableFn
type AddFunction = InvokableFn<[arg1: number, arg2: number], number>;
// Equivalent to:
type TraditionalFunction = (arg1: number, arg2: number) => number;
Object Invokable (IInvokableObject)
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 { IInvokableObject } from "@daiso-tech/core/utilities";
class InvokableObject
implements IInvokableObject<[arg1: number, arg2: number], number>
{
invoke(arg1: number, arg: number2): number {
throw new Error("Method not implemented.");
}
}
const invokableObject: IInvokableObject<[arg1: number, arg2: number], number> =
{
invoke(arg1: number, arg: number2): number {
throw new Error("Method not implemented.");
},
};
Further information
For further information refer to @daiso-tech/core/utilities API docs.