Menu

1 / 2

AI SDK 7.0.163 Added Two Stream Parts in a Patch Release. My Exhaustive Switch Stopped Compiling

DEV Community: typescript·Sushil·7 days ago
#tPuInOOG
#devtotypescript#devto#dev#case#part
Reading 0:00
15s threshold

If you loop over fullStream from streamText and switch on part.type with an assertNever fallback, bumping ai from 7.0.162 to anything from 7.0.163 up will break your type check. Nothing is wrong at runtime. The union just got two new members in a patch release.

I hit this on purpose to see exactly what changes, so here's the error, why it happens, and the fix.

The error

This is a normal exhaustive handler. It compiles cleanly against [email protected] :

import type { TextStreamPart , ToolSet } from ' ai ' ;

function assertNever ( value : never ): never { throw new Error ( `Unhandled stream part: ${ JSON . stringify ( value )} ` ); }

export function describePart ( part : TextStreamPart < ToolSet > ): string { switch ( part . type ) { case ' start ' : case ' start-step ' : case ' finish-step ' : case ' finish ' : return part . type ; case ' text-start ' : case ' text-end ' : case ' reasoning-start ' : case ' reasoning-end ' : return part . type ; case ' text-delta ' : case ' reasoning-delta ' : return part .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.