Skip to content

Commit 1861a48

Browse files
committed
fix: 布尔值在枚举类型中被解析为字符串类型
1 parent 3c3d261 commit 1861a48

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/lib/parse-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const parseSchema = (
1212
if (ofType) return `(${ofType}${nullable})`;
1313

1414
if (parsed.enum?.length) {
15-
return `(${parsed.enum.map((item) => (typeof item === 'number' ? item : `"${item}"`)).join(' | ')}${nullable})`;
15+
return `(${parsed.enum.map((item) => (typeof item === 'number' || typeof item === 'boolean' ? item : `"${item}"`)).join(' | ')}${nullable})`;
1616
}
1717

1818
switch (parsed.type) {

test/lib/parse-schema.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ describe('常规', () => {
8989

9090
test('枚举', () => {
9191
expect(
92-
parseSchema(docs, { enum: ['foo', 'bar', 'baz', 1, 2] }),
93-
).toMatchInlineSnapshot(`"("foo" | "bar" | "baz" | 1 | 2)"`);
92+
parseSchema(docs, { enum: ['foo', 'bar', 'baz', 1, 2, true, false] }),
93+
).toMatchInlineSnapshot(`"("foo" | "bar" | "baz" | 1 | 2 | true | false)"`);
9494
});
9595

9696
test('bigint转为字符串', () => {

0 commit comments

Comments
 (0)