Type 'DocumentType<"Blog">' is not assignable to type 'DocumentType<string>'
See original GitHub issueHey there… I started getting this error with v 0.0.30
, it was working fine with v 0.0.27
./contentlayer.config.ts:160:19
Type error: Type 'DocumentType<"Blog">' is not assignable to type 'DocumentType<string>'.
Types of property 'def' are incompatible.
Type 'Thunk<DocumentTypeDef<"Blog">>' is not assignable to type 'Thunk<DocumentTypeDef<string>>'.
Type 'DocumentTypeDef<"Blog">' is not assignable to type 'DocumentTypeDef<string>'.
Types of property 'computedFields' are incompatible.
Type 'ComputedFields<"Blog"> | undefined' is not assignable to type 'ComputedFields<string> | undefined'.
Type 'ComputedFields<"Blog">' is not assignable to type 'ComputedFields<string>'.
Type 'string' is not assignable to type '"Blog"'.
158 | const contentLayerConfig = makeSource({
159 | contentDirPath: 'data',
> 160 | documentTypes: [Blog, InspirationItem],
| ^
161 | mdx: {
162 | remarkPlugins: [remarkGfm],
163 | rehypePlugins: [
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
This is the content of contentlayer.config.ts
import { ComputedFields, defineDocumentType, makeSource } from 'contentlayer/source-files';
import readingTime from 'reading-time';
import rehypeAutolinkHeadings from 'rehype-autolink-headings';
import rehypeSlug from 'rehype-slug';
import remarkGfm from 'remark-gfm';
const computedFields: ComputedFields = {
readingTime: { type: 'json', resolve: (doc) => readingTime(doc.body.raw) },
slug: {
type: 'string',
// eslint-disable-next-line no-underscore-dangle
resolve: (doc) => doc._raw.sourceFileName.replace(/\.mdx$/, ''),
},
};
const Blog = defineDocumentType(() => ({
name: 'Blog',
filePathPattern: 'posts/*.mdx',
bodyType: 'mdx',
fields: {
title: { type: 'string', required: true },
date: { type: 'string', required: true },
hero: { type: 'string', required: true },
excerpt: { type: 'string' },
description: { type: 'string' },
author: { type: 'json' },
ogImage: { type: 'json' },
},
computedFields,
}));
const computedInspirationFields: ComputedFields = {
favicon: {
type: 'string',
resolve: async (doc) => {
return `${doc.link}/static/images/favicon.png`;
},
},
};
export const InspirationItem = defineDocumentType(() => ({
name: 'InspirationItem',
filePathPattern: 'inspiration/*.json',
fields: {
title: { type: 'string', required: true },
link: { type: 'string', required: true },
favicon: { type: 'string' },
},
computedFields: computedInspirationFields,
}));
export default makeSource({
contentDirPath: 'data',
documentTypes: [Blog, InspirationItem],
mdx: {
remarkPlugins: [remarkGfm],
rehypePlugins: [rehypeSlug, rehypeAutolinkHeadings],
},
});
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Typescript error: Type 'Document[]' is not assignable to custom ...
The error implies a mismatch between the type you're expecting MyDataset and the one Collection.find({}).toArray() is returning.
Read more >TypeScript: Document type not passed along with collection ...
When updating a document in that collection using a query for _id , TypeScript shows the error "TS2322: Type 'string' is not assignable...
Read more >Argument of type 'Document' is not assignable to parameter of ...
There is the solution of this error is here: Just only add this below line on top of ts file. declare var $:any;...
Read more >Type 'undefined' is not assignable to type in TypeScript
The "Type 'undefined' is not assignable to type" error occurs when a possibly undefined value is assigned to something that expects a different...
Read more >Documentation - Everyday Types - TypeScript
In this chapter, we'll cover some of the most common types of values you'll find in JavaScript code, and explain the corresponding ways...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should be fixed with https://github.com/contentlayerdev/contentlayer/releases/tag/v0.0.31
@schickling just created this repo: https://github.com/jahirfiquitiva/contentlayer-blog
I noticed the issue happens when I set multiple
documentTypes
(as seen in this commit)