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

`collection().columns` should allow `array` fields (runtime works, types reject them)

オープン 初心者向け
#1,548 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

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

調査の方向性

dist/declarations/src/config.d.ts の生成された宣言から始め、collection() の columns オプションのソース宣言を見つけます。既存の scalar フィールドと slug フィールドの型制約を確認し、array フィールドが受け入れられる一方で、サポートされていないフィールドが引き続き拒否されることを検証します。利用可能であれば、プロジェクトの TypeScript チェックまたは型テストスイートで完了を確認します。

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

説明

Problem

We want to show an array field in a collection list view via the columns option. For example, a list of external project slugs so editors can see at a glance which entries are linked to another system:

steckbriefe: collection({
  label: 'Steckbriefe',
  slugField: 'slug',
  path: 'src/data/steckbriefe/*/',
  format: { data: 'yaml' },
  columns: ['title', 'state', 'trassenscoutProjectSlugs', 'lastCheckedDate'],
  schema: {
    title: fields.text({ label: 'Titel', validation: { isRequired: true } }),
    trassenscoutProjectSlugs: fields.array(fields.text({ label: 'Trassenscout slug' }), {
      label: 'Trassenscout',
      itemLabel: (props) => props.value || 'Slug',
    }),
    // ...
  },
}),

Runtime: This works. The Admin UI renders array column values by stringifying them (val + ''), so ['rs8', 'rs8-north'] shows as rs8,rs8-north and [] shows as empty.

Types: TypeScript rejects trassenscoutProjectSlugs in columns because collection() only allows keys whose schema field is a scalar FormField or SlugFormField:

// dist/declarations/src/config.d.ts (current)
columns?: {
  [K in keyof Schema]: Schema[K] extends
    | FormField<any, any, string | number | boolean | Date | null | undefined>
    | SlugFormField<any, any, any, string>
    ? K & string
    : never;
}[keyof Schema][];

ArrayField (kind: 'array') is excluded even though the list view handles it fine.

Expected behavior

Array fields should be valid in columns, since the collection table already displays them.

Actual behavior
  • Admin UI: works
  • TypeScript: error — Type '"trassenscoutProjectSlugs"' is not assignable to type ...
Suggested fix

Extend the columns mapped type to also allow ArrayField keys:

columns?: {
  [K in keyof Schema]: Schema[K] extends
    | FormField<any, any, string | number | boolean | Date | null | undefined>
    | SlugFormField<any, any, any, string>
    ? K & string
    : Schema[K] extends { kind: 'array' }
      ? K & string
      : never;
}[keyof Schema][];
Environment
  • @keystatic/core: 0.5.50
  • @keystatic/astro: 5.1.0
  • TypeScript: 6.x
  • Package manager: Bun 1.3

Workarounds (until upstream fix)

Option A: @ts-expect-error (minimal)
steckbriefe: collection({
  // Keystatic renders array columns as comma-separated values; types only allow scalars.
  // @ts-expect-error array field used as list column
  columns: ['title', 'state', 'trassenscoutProjectSlugs', 'lastCheckedDate'],
  schema: {
    trassenscoutProjectSlugs: fields.array(fields.text({ label: 'Trassenscout slug' }), {
      label: 'Trassenscout',
    }),
    // ...
  },
}),
Option B: Patch @keystatic/core (what we use)

We patch the published type definition so columns accepts array fields without suppressions.

1. Start a patch (Bun):

bun patch @keystatic/core

2. Edit node_modules/@keystatic/core/dist/declarations/src/config.d.ts:

     columns?: {
-        [K in keyof Schema]: Schema[K] extends FormField<any, any, string | number | boolean | Date | null | undefined> | SlugFormField<any, any, any, string> ? K & string : never;
+        [K in keyof Schema]: Schema[K] extends FormField<any, any, string | number | boolean | Date | null | undefined> | SlugFormField<any, any, any, string> ? K & string : Schema[K] extends {
+            kind: 'array';
+        } ? K & string : never;
     }[keyof Schema][];

3. Commit the patch:

bun patch --commit 'node_modules/@keystatic/core'

This creates patches/@keystatic%[email protected] and adds to package.json:

"patchedDependencies": {
  "@keystatic/[email protected]": "patches/@keystatic%[email protected]"
}

Bun reapplies the patch on every bun install. After upgrading @keystatic/core, regenerate the patch for the new version.

主要言語
TypeScript
スター
2.4k
フォーク
164
平均マージ
5時間 46分
マージ済み PR(30日)
3

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

Thinkmill/keystatic のほかの issue

Thinkmill/keystatic の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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