diff --git a/.changeset/issue-8378-usechat-options-cast.md b/.changeset/issue-8378-usechat-options-cast.md new file mode 100644 index 0000000000..5b130b58a4 --- /dev/null +++ b/.changeset/issue-8378-usechat-options-cast.md @@ -0,0 +1,11 @@ +--- +--- + +Removes the inert blanket `as any` on `useChat`'s options object in +`useObjectChat` (objectui#8378). Publishes nothing: the assertion lives inside a +function body whose export already carries an explicit return-type annotation, so +it is erased at emit. Measured rather than assumed — building +`@object-ui/plugin-chatbot` from this branch and from the merge-base produced a +byte-identical `dist` across all 34 published artifacts (`.d.ts`, `.js`, `.cjs`, +`.css`), and the comparison was proved live by a control mutation to an emitted +string literal, which the same comparison reported as differing. diff --git a/packages/plugin-chatbot/src/useObjectChat.ts b/packages/plugin-chatbot/src/useObjectChat.ts index ff06f46f94..0c3c0da625 100644 --- a/packages/plugin-chatbot/src/useObjectChat.ts +++ b/packages/plugin-chatbot/src/useObjectChat.ts @@ -701,6 +701,14 @@ export function useObjectChat(options: UseObjectChatOptions = {}): UseObjectChat const chatRef = useRef(null); const chatResult = useChat({ transport, + // The `as any` here is the LIVE suppression on this call, and it is the only + // one: `aiInitialMessages` builds `parts` as `Record[]`, which + // is not a `UIMessagePart` union, so dropping this cast turns the call red with + // TS2322 (measured, objectui#8378). The blanket `as any` that used to sit on the + // whole options object was removed there because it hid nothing this one does not + // already absorb — but it also switched off checking of `transport`, `onError` + // and excess properties. Fix the builder before deleting this cast; do NOT + // re-widen the call by casting the options object again. messages: isApiMode && aiInitialMessages.length > 0 ? (aiInitialMessages as any) : undefined, onError: isApiMode ? (err: Error) => { @@ -732,7 +740,7 @@ export function useObjectChat(options: UseObjectChatOptions = {}): UseObjectChat onError?.(err); } : undefined, - } as any); + }); chatRef.current = chatResult; // ADR-0057 #8 — refresh the AI usage indicator when a turn finishes. On the