fuma-nama / fumadocs

The beautiful docs framework with Next.js. Alternative to Nextra
https://fumadocs.vercel.app
MIT License
1.86k stars 113 forks source link

tsconfig "exactOptionalPropertyTypes" incompatible with createMDXSource #843

Closed Yonom closed 2 months ago

Yonom commented 2 months ago

To Reproduce

In a fumadocs project, enable exactOptionalPropertyTypes:

{
  "compilerOptions": {
    "exactOptionalPropertyTypes": true, // add this
  }
}

Then restart TS server / attempt a build: The /app/source.ts file has build errors.

Current vs. Expected behavior

createMDXSource is not able to infer the types of the collections

Screenshot 2024-09-09 at 23 02 30
Argument of type 'GetOutput<Collections<ZodObject<{ title: ZodString; description: ZodOptional<ZodString>; icon: ZodOptional<ZodString>; full: ZodOptional<ZodBoolean>; _openapi: ZodOptional<...>; }, "strip", ZodTypeAny, { ...; }, { ...; }>, "doc", CollectionEntry<...>>>' is not assignable to parameter of type 'CollectionEntry<"doc", PageData>[]'.
  Type 'CollectionEntry<"doc", { title: string; icon?: string | undefined; description?: string | undefined; full?: boolean | undefined; _openapi?: objectOutputType<{}, ZodTypeAny, "passthrough"> | undefined; }>' is not assignable to type 'CollectionEntry<"doc", PageData>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
    Type 'CollectionEntry<"doc", { title: string; icon?: string | undefined; description?: string | undefined; full?: boolean | undefined; _openapi?: objectOutputType<{}, ZodTypeAny, "passthrough"> | undefined; }>' is not assignable to type 'PageData' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
      Types of property 'icon' are incompatible.
        Type 'string | undefined' is not assignable to type 'string'.
          Type 'undefined' is not assignable to type 'string'.

Provide environment information

Node.js v20.15.0

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 20.15.0
  npm: 10.7.0
  Yarn: N/A
  pnpm: 9.10.0
Relevant Packages:
  next: 14.2.9 // Latest available version is detected (14.2.9).
  eslint-config-next: 14.2.9
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.6.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Content Sources (e.g. Fumadocs MDX, Content Collections)

Additional context

No response