contentlayerdev / contentlayerdev/contentlayer

Enable specifying list type in computed fields

Open
#277 2 comments 2 reactions 0 assignees View on GitHub
improvement meta: never-stale topic: schema
Dominant language
TypeScript
Stars
3.5k
Forks
192
PR merge metrics
No merged PRs in 30d

Description

As far as I can tell, it isn't possible to specify the `of` type of lists in computed fields the way that you can in non-computed fields. Thus, this is possible:

```typescript
fields: {
tags: {
type: "list",
of: { type: "string" },
default: []
}
}
```

But this is not:

```typescript
computedFields: {
segments: {
type: "list",
of: { type: "string" },
resolve: (doc) => { ... }
}
}
```

Instead, you can only specify an untyped list, and in the generated output you end up with this:

```typescript
segments: list
```

But this raw `list` type isn't defined!

There may be reasons to explicitly disallow typed lists in computed fields, and if so I'd be curious why! Otherwise, this feels like an oversight to me.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.