Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Make it easier to share field definitions

オープン
#147 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript

調査の方向性

defineDocumentType API から始めて、Contentlayer 内で FieldDef と ReferencePolymorphicFieldDef の型定義またはエクスポートを探します。sharedFields.title と sharedFields.url がどのように推論されるかを確認し、再利用可能なフィールド定義が type-check できるかどうか、また推奨される userland のアプローチとして何を文書化すべきかを判断します。

索引モデルが issue の本文から書いたものです。

説明

meta: never-stale topic: typescript

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:

  1. Get it to work by importing types from Contentlayer.
  2. Considering these types to be userland code, let's find a cleaner recommended implementation approach for devs.
主要言語
TypeScript
スター
3.5k
フォーク
192
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

contentlayerdev/contentlayer のほかの issue

contentlayerdev/contentlayer の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。