Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix batchRenderUserMessages() type #4198

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions front/lib/api/assistant/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ export async function deleteConversation(
* Conversation Rendering
*/

export async function batchRenderUserMessages(messages: Message[]) {
export async function batchRenderUserMessages(
messages: Message[]
): Promise<{ m: UserMessageType; rank: number; version: number }[]> {
const userMessages = messages.filter(
(m) => m.userMessage !== null && m.userMessage !== undefined
);
Expand Down Expand Up @@ -241,14 +243,15 @@ export async function batchRenderUserMessages(messages: Message[]) {
user: user
? {
id: user.id,
createdAt: user.createdAt.getTime(),
username: user.username,
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
fullName:
user.firstName + (user.lastName ? ` ${user.lastName}` : ""),
provider: user.provider,
image: user.imageUrl,
workspaces: [],
}
: null,
mentions: messageMentions.map((m) => {
Expand All @@ -267,7 +270,7 @@ export async function batchRenderUserMessages(messages: Message[]) {
email: userMessage.userContextEmail,
profilePictureUrl: userMessage.userContextProfilePictureUrl,
},
};
} satisfies UserMessageType;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From GPT4:

The satisfies Keyword: The satisfies keyword is a newer addition to TypeScript, introduced in TypeScript 4.9, aimed at type checking rather than type assertion. It allows you to check if a value satisfies a particular type without changing the value's type. This is particularly useful for object literals and ensuring they adhere to a specific shape or interface without changing their inferred type.

Without that, the type system was not able to infer the right type in this code. So I initially added it to highlight what was wrong, and realized that it helped the type checker inferring it correctly.

return { m, rank: message.rank, version: message.version };
});
}
Expand Down
Loading