contentlayerdev / contentlayerdev/contentlayer

overwrite `field` data with `computedFields` values

Đang mở
#398 2 bình luận 4 reaction 0 người được giao Xem trên GitHub
meta: never-stale needs-research
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

Mô tả

When defining a document with a `field` and `computedFields` child item with the same name, the `computedFields` field seems to be appended onto the generated type. Resulting in undesired types for the field.

I would have expected the `computedFields` data to overwrite the `field` data, both the `description` and the `type`.

For reference, I am converting a comma separated string of `tags` into a parsed array via the `computedFields`. Here is an example of my document definition:

```js
export const Blog = defineDocumentType(() => ({
name: "Blog",
filePathPattern: `blog/**/*.md`,
fields: {
tags: {
type: "string",
description: "Comma separated listing of tags",
required: false,
},
},
computedFields: {
tags: {
description: "new description",
type: "list",
of: { type: "string" },
resolve: (item) =>
item?.tags?.split(",")?.map((tag) => tag.trim()) ?? undefined,
},
},
}));
```

Generates these types (simplified for the example):

```ts
/** Document types */
export type Blog = {
/** Comma separated listing of tags */
tags?: string | undefined
/** new description */
tags: list
}
```

Extra note: It also seems like the `computedFields` children do not support `list` types, or it may be a bug?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

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.