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

Enum values are not validated

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
tooling

調査の方向性

まず、frontmatter の値が options 配列に存在しない enum フィールドで問題を再現し、次に Contentlayer のビルドとスキーマ検証のエントリーポイントを追跡します。ビルドが無効な値を拒否し、有効な enum 値については引き続きドキュメントと TypeScript 型が生成されれば完了です。

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

説明

feature meta: never-stale topic: data validation

I've seen some examples on issues of people using a field of type enum to specify the page locale.

---
locale: 'en'
---
(...)
defineDocumentType(() => ({
    [...],
    fields: {
        locale: {
            type: 'enum',
            options: ['en', 'es', 'de'],
            required: true
        }
    }
}));

I've just seen on contentlayer@0.3.0 that if you have a file with an invalid enum value (not in the options array), then the build will complete successfully.

---
locale: 'not in the options array'
---
(...)
$ yarn contentlayer build
yarn run v1.22.19
$ /(...)/node_modules/.bin/contentlayer build
Generated 2 documents in .contentlayer
Done in 1.32s.

I understand that even if it does not validate values, the enum type field is really useful once it automatically generates TS types, but given that we can validate fields with required, shouldn't we also be able to validate the if the field value matches what we defined on the schema? (In the case of enum fields)

主要言語
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 を短くまとめたダイジェスト。