ConstThis schema checks for the presence of a next() method but cannot verify at
parse time that it returns a Promise. The async behavior is validated at
iteration time.
const asyncGen = (async function* () {
yield 1;
})();
AsyncIteratorSchema.parse(asyncGen); // ✓ Valid (async generator is also iterator)
AsyncIteratorSchema.parse({
next: async () => ({ done: true, value: undefined }),
}); // ✓ Valid
AsyncIteratorSchema.parse([1, 2, 3][Symbol.iterator]()); // ✓ Valid (has next())
AsyncIteratorSchema.parse({}); // ✗ Throws validation error
Schema matching any asynchronous iterator (has async
next()method).This schema validates values that implement the async iterator protocol, meaning they have a
next()method that returns a Promise of{ value, done }. This includes async iterator objects and custom async iterator implementations.