contentlayerdev / contentlayerdev/contentlayer

Support referencing TS type definitions for `type: 'json'` fields

Open
#26 3 comments 5 reactions 0 assignees View on GitHub
feature pkg/source-files
Dominant language
TypeScript
Stars
3.5k
Forks
192
PR merge metrics
No merged PRs in 30d

Description

In some cases where you're using `type: 'json'` you'd like to reference some existing TS type definitions instead of the `any` type that's currently used for `json` fields. This applies to both regular `fields` and `computedFields`.

Example:

![image](https://user-images.githubusercontent.com/1567498/140750539-bb4b8f33-517a-4afd-bfdc-df2a767c2767.png)

Rough API idea:

```ts
{
// ...
typescriptType: { name: 'IReadTimeResults', from: 'reading-time' }
}
```

## Notes

- A potential other direction/idea for this could be to "derive" nested document types based on existing TS types. (Would address #149)

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.