forked from run-llama/LlamaIndexTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.test.ts
56 lines (54 loc) · 1.51 KB
/
type.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { ChatMessage, MessageContent, MessageType } from "llamaindex";
import { expectTypeOf, test } from "vitest";
import type { ChatResponse } from "../src/index.js";
test("chat message type", () => {
// if generic is not provided, `options` is not required
expectTypeOf<ChatMessage>().toMatchTypeOf<{
content: MessageContent;
role: MessageType;
}>();
expectTypeOf<ChatMessage>().toMatchTypeOf<{
content: MessageContent;
role: MessageType;
options?: object | undefined;
}>();
expectTypeOf<ChatMessage>().not.toMatchTypeOf<{
content: MessageContent;
role: MessageType;
options: Record<string, unknown>;
}>();
type Options = {
a: string;
b: number;
};
expectTypeOf<ChatMessage<Options>>().toMatchTypeOf<{
content: MessageContent;
role: MessageType;
options?: Options | undefined;
}>();
});
test("chat response type", () => {
// if generic is not provided, `options` is not required
expectTypeOf<ChatResponse>().toMatchTypeOf<{
message: ChatMessage;
raw: object | null;
}>();
expectTypeOf<ChatResponse>().toMatchTypeOf<{
message: ChatMessage;
raw: object | null;
options?: Record<string, unknown>;
}>();
expectTypeOf<ChatResponse>().not.toMatchTypeOf<{
message: ChatMessage;
raw: object | null;
options: Record<string, unknown>;
}>();
type Options = {
a: string;
b: number;
};
expectTypeOf<ChatResponse<Options>>().toMatchTypeOf<{
message: ChatMessage<Options>;
raw: object | null;
}>();
});