Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] A Collection defined with defineCollection causes a type error when included in defineConfig's collections. #205

Open
wontory opened this issue Aug 9, 2024 · 4 comments

Comments

@wontory
Copy link

wontory commented Aug 9, 2024

Property '_cached' of exported class expression may not be private or protected.ts(4094)

If there are no Collections inside the collections of defineConfig, no error occurs.
However, if Collections are added, an error occurs.

This is my full source code of velite.config.ts.
And this code was written with reference to the velite.config.ts from Velite's taxonomy.

import { defineCollection, defineConfig, s } from 'velite'
import remarkGfm from 'remark-gfm'
import rehypeSlug from 'rehype-slug'
import rehypeAutolinkHeadings from 'rehype-autolink-headings'

const computedFields = <T extends { slug: string }>(data: T) => ({
  ...data,
  slugAsParams: data.slug.split('/').slice(1).join('/'),
})

const posts = defineCollection({
  name: 'Post',
  pattern: 'posts/**/*.mdx',
  schema: s
    .object({
      slug: s.path(),
      title: s.string().max(99),
      description: s.string().max(999).optional(),
      date: s.isodate(),
      published: s.boolean().default(true),
      image: s.image(),
      authors: s.array(s.string()),
      toc: s.toc(),
      body: s.mdx(),
    })
    .transform(computedFields),
})

const authors = defineCollection({
  name: 'Author',
  pattern: 'authors/**/*.mdx',
  schema: s
    .object({
      slug: s.path(),
      title: s.string().max(99),
      description: s.string().max(999).optional(),
      avatar: s.string().max(99),
      github: s.string().max(99),
      body: s.mdx(),
    })
    .transform(computedFields),
})

export default defineConfig({
  root: 'content',
  output: {
    data: '.velite',
    assets: 'public/static',
    base: '/static/',
    name: '[name]-[hash:6].[ext]',
    clean: true,
  },
  collections: { posts, authors },
  mdx: {
    remarkPlugins: [remarkGfm],
    rehypePlugins: [
      rehypeSlug,
      [
        rehypeAutolinkHeadings,
        {
          properties: {
            className: ['subheading-anchor'],
            ariaLabel: 'Link to section',
          },
        },
      ],
    ],
  },
})
@wontory wontory closed this as completed Aug 9, 2024
@moltar
Copy link

moltar commented Sep 21, 2024

@wontory I'm having the same issue. How did you resolve it? Thanks.

@wontory
Copy link
Author

wontory commented Oct 5, 2024

@wontory I'm having the same issue. How did you resolve it? Thanks.

@moltar
Are you using monorepo(like turborepo)?
Turborepo template's default tsconfig is causing error.

Try remove "declaration": true in tsconfig.json.

@moltar
Copy link

moltar commented Oct 5, 2024

I'm using monorepo, and I do use turbo, but I do not use the default tsconfig.

I do have the "declaration": true enabled tho. I'll try without it.

I don't understand why it'd be causing the problem by itself? Can you please explain the reason you believe this causes the problem.

I think that optionjust tells tsc to create *.d.ts files on compile. Given that I use Remix & Vite bundler, I think there should be no declaration files anyways.

@wontory wontory reopened this Oct 5, 2024
@wontory
Copy link
Author

wontory commented Oct 5, 2024

@moltar
I don't know the exact reason, but I think the link below can explain it.
Re-opening the issue.

Stack Overflow: Typescript allows to use proper multiple inheritance with mixins, but fails to create delcaration files

microsoft/TypeScript#30355

@wontory wontory changed the title A Collection defined with defineCollection causes a type error when included in defineConfig's collections. [FIX] A Collection defined with defineCollection causes a type error when included in defineConfig's collections. Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants