zod 4 toJSONSchema() throws a deferred SC2011 in finalize (Map entries spread)

Đang mở
#3,605 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
typescript
Lĩnh vực
compilers

Hướng nghiên cứu

Start by reproducing with the minimal index.ts (a z.object calling toJSONSchema()) and the scriptc build command from the issue, then read the failing line 295 of node_modules/zod/v4/core/to-json-schema.js, which spreads ctx.seen.entries() in finalize. The payload does not name the compiler source that emits SC2011, so the first step is locating where that diagnostic is raised for untyped Map entries. Done means the probe prints the expected draft 2020-12 JSON Schema without the SC2011 error.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

toJSONSchema() from zod 4.4.3 compiles, but throws at run time with a deferred SC2011 inside zod's finalize.

index.ts:

import { z } from "zod";

console.log(JSON.stringify(z.object({ a: z.string() }).toJSONSchema()));

With [email protected] installed and a tsconfig.json of {"compilerOptions":{"target":"ES2022","module":"NodeNext","moduleResolution":"NodeNext","strict":true}}, scriptc build index.ts -o probe --optimization dev --node-islands=off builds (0.4.10 and 0.4.11). Running ./probe:

scriptc: not compiled: values of type 'any' have no native representation at this site (instantiating 'finalize' with ({ counter: number; cycles: unknown; external: unknown; io: unknown; metadataR...)) [SC2011 at node_modules/zod/v4/core/to-json-schema.js:295]
Uncaught Error: values of type 'any' have no native representation at this site (instantiating 'finalize' with ...) [SC2011 at node_modules/zod/v4/core/to-json-schema.js:295]
    at finalize (node_modules/zod/v4/core/to-json-schema.js:295:5)

Node prints {"$schema":"https://json-schema.org/draft/2020-12/schema","type":"object","properties":{"a":{"type":"string"}},"required":["a"],"additionalProperties":false}.

Line 295 of to-json-schema.js is

for (const entry of [...ctx.seen.entries()].reverse()) {

where ctx.seen is a Map built in initializeContext (seen: new Map()), keyed by schema with untyped entry objects. The same happens through schema["~standard"].jsonSchema.input(...) and z.toJSONSchema(schema), which all reach finalize.

Programs that hand zod schemas to the MCP SDK (tool listings) or build structured-output prompts with z.toJSONSchema hit this.

Ngôn ngữ chính
TypeScript
Star
6.6k
Fork
216
Merge trung bình
9 giờ 35 phút
Pull request đã merge (30 ngày)
775

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của vercel-labs/scriptc

Tất cả issue của vercel-labs/scriptc

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.