Const
The schema is registered in the BupkisRegistry
with the name
AsyncFunctionSchema
for later reference and type checking purposes. This
schema cannot reliably detect functions that return Promises but are not
declared with async
, as this determination requires static analysis that is
not available at runtime.
async function asyncFn() {
return 42;
}
AsyncFunctionSchema.parse(asyncFn); // ✓ Valid
const asyncArrow = async () => 42;
AsyncFunctionSchema.parse(asyncArrow); // ✓ Valid
function syncFn() {
return Promise.resolve(42);
}
AsyncFunctionSchema.parse(syncFn); // ✗ Throws validation error
const regularFn = () => 42;
AsyncFunctionSchema.parse(regularFn); // ✗ Throws validation error
A Zod schema that validates functions declared with the
async
keyword.This schema validates functions that are explicitly declared as asynchronous using the
async
keyword. It uses runtime introspection to check the function's internal[[ToString]]
representation to distinguish async functions from regular functions that might return Promises.