OnFinishResult Type

I was looking at this part of the document on using onFinish callback.

The document provides that the callback function take a parameter of OnFinishResult type. Can anyone please help me understand how to import this type? I’d be useful if I write the callback in other places than the inline function.

Currently my IDE is suggesting type “any”.

async function onFinishCallback(result: any): Promise<void> {
    // This function is called when the AI has finished generating a response.
    console.log('\nAI response finished:', result);   
}
const result = streamText({
        model: google('gemini-2.5-flash-preview-05-20'),
        system: 'you are an assistant.',
        messages,
        providerOptions: /*something*/,
        onFinish: onFinishCallback,
    });
1 Like

I found this line can be useful to define the type.

let onFinishResult: Parameters<
      Required<Parameters<typeof streamText>[0]>['onFinish']
    >[0];
1 Like

Looks like you are right. I looked around in the codebase and didn’t see any official OnFinishResult type (besides the type you mentioned used in testing). I might make a PR for this :smiley:

1 Like

I did create a PR, but it’s very small and maybe not necessary with the workarounds discussed here :smiling_face_with_tear:

2 Likes