Skip to main content

Function: createFunctionPrecondition()

createFunctionPrecondition(precondition: FunctionPrecondition, fallback: FunctionFallback): MethodDecorator

Utility to make function preconditions.

// No fallback (returns undefined)
function requireGuild(value: number) {
return createFunctionPrecondition((message: Message) =>
message.guild !== null
);
}

// With fallback
function requireGuild(
value: number,
fallback: () => unknown = () => undefined
) {
return createFunctionPrecondition(
(message: Message) => message.guild !== null,
fallback
);
}

Parameters

ParameterTypeDescription
preconditionFunctionPreconditionThe function that defines whether or not the function should be run, returning the returned value from fallback
fallbackFunctionFallbackThe fallback value that defines what the method should return in case the precondition fails

Returns

MethodDecorator

Since

1.0.0

Source

utils.ts:73