Assistants Messages has problem with TypeScript

Hello I am using the assistants API and when I list the latest message from the assistant using:

lastMessageForRun.content[0].text.value

I get a TypeScript Error that text does not exist:

Property 'text' does not exist on type 'MessageContent'.
  Property 'text' does not exist on type 'ImageFileContentBlock'.ts(2339)

Even though it works fine the only option that seems to be available from the types is .content[0].type, everything else provides an error.

1 Like

You can look at my code how I do it and i use the following type to make sure I don’t have any TS error

import { Message } from “openai/resources/beta/threads/messages.mjs”;

1 Like

How does your code deal with a content[0] of pydantic class ImageFileContentBlock?

It seems that OpenAI implementation is correct, I just needed to check the type before accessing .text.

if (message.content[0].type == 'text') {
              response = message.content[0].text.value
}

This removes the error.

1 Like