Why did the type of GenerateReturn change?

before
export type GenerateReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined
? GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>
: GenerateObjectResult<Z extends ZodSchema ? z.infer<Z> : unknown>;
export type GenerateReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined
? GenerateTextResult<any, Z extends ZodSchema ? z.infer<Z> : unknown>
: GenerateObjectResult<Z extends ZodSchema ? z.infer<Z> : unknown>;
after
export type GenerateReturn<
Tools extends ToolSet,
Output extends ZodSchema | JSONSchema7 | undefined = undefined,
StructuredOutput extends ZodSchema | JSONSchema7 | undefined = undefined,
> = GenerateTextResult<Tools, StructuredOutput> | GenerateObjectResult<Output>;
export type GenerateReturn<
Tools extends ToolSet,
Output extends ZodSchema | JSONSchema7 | undefined = undefined,
StructuredOutput extends ZodSchema | JSONSchema7 | undefined = undefined,
> = GenerateTextResult<Tools, StructuredOutput> | GenerateObjectResult<Output>;
If output is specified in the generate function, the return type will be GenerateObjectResult and no compile error will occur when accessing response.object. Why can't I infer text response and object response in this way? https://github.com/mastra-ai/mastra/pull/5965 I saw this PR, but can't it be a conditional type instead of just an intersection type?
GitHub
streaming v2 by wardpeet · Pull Request #5965 · mastra-ai/mastra
Introducing streamVNext A new streaming protocol that allows us to stream all mastra primitives, agent, tools, workflows. (soon networks). Our old protocol was based on Vercel&amp;#39;s AI sdk data...
5 Replies
kosukeoya
kosukeoyaOP4mo ago
My project is giving me tons of compile errors when I update to the latest version. Please help @Ward
dero
dero4mo ago
Hi @kosukeoya when output is specified, response.object not throwing any compile error is the correct behaviour as it provides the structured output can you help with a screenshot of the compile errors your'e seeing? and how you're implementing in code?
kosukeoya
kosukeoyaOP4mo ago
https://github.com/mastra-ai/mastra/pull/6185 I forgot to leave the information here. I created a PR of the fix and it was merged.
GitHub
Fix/generate return types inference by kosukeoya · Pull Request #6...
Description The GenerateReturn type has been modified in this PR. #5965 before export type GenerateReturn&amp;lt;Z extends ZodSchema | JSONSchema7 | undefined = undefined&amp;gt; = Z extends undef...
dero
dero4mo ago
That's great. Thanks for contributing!

Did you find this page helpful?