tRPCttRPC
Powered by
fjjfjfjF
tRPC•6mo ago
fjjfjfj

Output validator for Async generators on a streaming procedure using Zod

Might be a bit of a long shot but I was curious if anyone else has managed to do this?
Im just getting typescript errors as it wants the query return type to be a
MaybePromise<T>
MaybePromise<T>
when I have
AsyncGenerator<T>
AsyncGenerator<T>
and there doesnt seem to be anything in zod (apart from brute forcing through custom, which defeats the purpose) to make this work.
Keen to here anyones thoughts!

  test: publicProcedure.output(z.number()).query(async function*() {
    for (let i = 0; i < 10; i++) {
      yield new Promise<number>(r => setTimeout(() => r(i), i * 1000));
    }
  })
  test: publicProcedure.output(z.number()).query(async function*() {
    for (let i = 0; i < 10; i++) {
      yield new Promise<number>(r => setTimeout(() => r(i), i * 1000));
    }
  })

Type 'AsyncGenerator<number, void, unknown>' is not assignable to type 'MaybePromise<number>'.
Type 'AsyncGenerator<number, void, unknown>' is not assignable to type 'MaybePromise<number>'.
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

procedure output is "any"
stuSstu / ❓-help
15mo ago
Using output validator breaks query return type inference on react query
KarolKKarol / ❓-help
2y ago
Zod Output validation failed
JohnyJJohny / ❓-help
9mo ago