Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Improve error handling for polymorphic field data with missing type value

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

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

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
data

Hướng nghiên cứu

Bắt đầu trong packages/@contentlayer/core/src/generation/generate-dotpkg.ts, đặc biệt là idToFileName và luồng makeDataExportFile xung quanh nó. Tái hiện ví dụ danh sách lồng nhau đa hình bằng TypeScript, theo dõi cách giá trị kiểu bị thiếu đi tới quá trình tạo và xác minh rằng trường hợp này tạo ra một lỗi được xử lý hữu ích thay vì TypeError undefined.replace đã được báo cáo.

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

Mô tả

good first issue help wanted meta: never-stale topic: error-handling

I encountered an error with following code trying to add polymorphic nested objects to a list.

export const Link = defineNestedType(() => ({
    name: "Link",
    description: "Link to an external resource",
    fields: {
        text: {
            type: "string",
            required: true,
        },
        url: {
            type: "string",
            required: true,
        },
    },
}));

export const LinkList = defineNestedType(() => ({
    name: "LinkList",
    description: "List of links to external resources",
    fields: {
        text: {
            type: "string",
            required: true,
        },
        links: {
            type: "list",
            required: true,
            of: Link,
        },
    },
}));

export const NavbarLinks = defineDocumentType(() => ({
    name: "NavbarLinks",
    filePathPattern: "core/navbarLinks.json",
    isSingleton: true,
    fields: {
        links: {
            type: "list",
            of: [Link, LinkList],
            required: true,
        },
    },
}));

This produces following stack trace

TypeError: Cannot read properties of undefined (reading 'replace')
    at idToFileName (file://.../node_modules/@contentlayer/core/src/generation/generate-dotpkg.ts:389:89)
    at makeDataExportFile (file://.../node_modules/@contentlayer/core/src/generation/generate-dotpkg.ts:291:53)
    at file://.../node_modules/@contentlayer/core/src/generation/generate-dotpkg.ts:153:18
    at Array.map (<anonymous>)
    at next (file://.../node_modules/@contentlayer/core/src/generation/generate-dotpkg.ts:152:44)
    at Generator.next (<anonymous>)
    at ApplyFrame.apply (file://.../node_modules/@effect-ts/system/_src/Effect/gen.ts:148:36)
    at FiberContext.nextInstr (file://.../node_modules/@effect-ts/system/_src/Fiber/context.ts:357:28)
    at FiberContext.evaluateNow (file://.../node_modules/@effect-ts/system/_src/Fiber/context.ts:940:36)
    at file://.../node_modules/@effect-ts/system/_src/Fiber/context.ts:576:33

Fiber: #17 (started at: 2022-09-04T21:49:21.161Z) was supposed to continue to:

  a future continuation at packages/@contentlayer/core/src/generation/generate-dotpkg.ts:216:13

Fiber: #17 (started at: 2022-09-04T21:49:21.161Z) Execution trace:

  packages/@contentlayer/core/src/generation/generate-dotpkg.ts:144:22
  packages/@contentlayer/core/src/generation/generate-dotpkg.ts:143:60
  packages/@contentlayer/core/src/generation/generate-dotpkg.ts:125:10
  packages/@contentlayer/core/src/generation/generate-dotpkg.ts:82:13
  packages/@contentlayer/core/src/generation/generate-dotpkg.ts:78:16
Ngôn ngữ chính
TypeScript
Star
3.5k
Fork
192
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

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 contentlayerdev/contentlayer

Tất cả issue của contentlayerdev/contentlayer

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.