Make it easier to share field definitions
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 42/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- typescript
研究方向
從 defineDocumentType API 開始,在 Contentlayer 中找出 FieldDef 和 ReferencePolymorphicFieldDef 的型別定義或匯出。檢查 sharedFields.title 和 sharedFields.url 是如何被推導的,接著判斷可重複使用的欄位定義是否能通過 type-check,以及應記錄哪種建議的 userland 作法。
由索引模型根據 Issue 內容生成。
描述
I'd love to be able to do something like this:
const sharedFields = {
title: (opts) => {
return {
type: "string",
required: true,
...opts
}
},
url: {
type: "string",
resolve: (doc) => doc._raw.flattenedPath,
}
}
export const Tag = defineDocumentType(() => ({
name: "Tag",
filePathPattern: `tags/**/*.md`,
fields: {
title: sharedFields.title,
color: {
type: "string",
description: "Color of the badge to show for the tag",
},
},
computedFields: {
url: sharedFields.url,
},
}));
The types from defineDocumentType are inferred by Contentlayer. But this process doesn't work because the correct types cannot be inferred from sharedFields.
For example, title throws the following:
(property) title: (opts: any) => any
Type '(opts: any) => any' is not assignable to type 'FieldDef'.
Type '(opts: any) => any' is not assignable to type 'ReferencePolymorphicFieldDef'.
Type '(opts: any) => any' is missing the following properties from type '{ type: "reference"; default?: string; of: readonly DocumentType<string>[]; typeField?: string; }': type, of
I'm assuming this is just a matter of bringing in the proper types from Contentlayer. I poked around for a bit, but couldn't find the right import path containing FieldDef and ReferencePolymorphicFieldDef.
I think there are two parts to this:
- Get it to work by importing types from Contentlayer.
- Considering these types to be userland code, let's find a cleaner recommended implementation approach for devs.
- 主要語言
- TypeScript
- 星號
- 3.5k
- 分支
- 192
- PR 合併指標
- 30 天內沒有已合併 PR
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
contentlayerdev/contentlayer 的其他 Issue
-
Error when building with contentlayer 0.3.4 and Next.js 13 App Router可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 3/5 1-2 天 新手友好度 25/100
contentlayerdev/contentlayer#506 · 84 則留言 · 47 個 reaction ·
-
Poor/broken monorepo DX: can't specify .contentlayer/ output path, no docs for custom config path未關閉help wanted meta: never-stale needs-research
難度 4/5 3-5 天 新手友好度 38/100
contentlayerdev/contentlayer#464 · 4 則留言 · 9 個 reaction ·
-
meta: never-stale
難度 5/5 一週以上 新手友好度 10/100
contentlayerdev/contentlayer#429 · 49 則留言 · 83 個 reaction ·
-
meta: never-stale topic: markdown/mdx
難度 4/5 3-5 天 新手友好度 42/100
contentlayerdev/contentlayer#421 · 4 個 reaction ·
-
meta: never-stale needs-research topic: schema
難度 5/5 一週以上 新手友好度 25/100
contentlayerdev/contentlayer#420 ·
查看 contentlayerdev/contentlayer 的全部 Issue
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 83/100
維護者通常 1 天內回覆
-
Feil lovtekst i bekreftelsen når leder melder unntak fra oppfølgingsplan可能已有人在做 @AudunSorheim 今天認領。 未關閉
難度 1/5 1 小時以內 新手友好度 92/100
navikt/syfo-oppfolgingsplan-frontend#1110 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
db-ux-design-system/core-web#8461 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
Cannot run an integration on windows when power shell is selected as the default profile terminal未關閉Priority/Blocker Type/Bug
難度 2/5 1-3 小時 新手友好度 76/100
wso2/product-integrator#2767 ·
維護者通常 1 天內回覆