brillout / vite-plugin-mdx

Vite Plugin for MDX
MIT License
113 stars 36 forks source link

Not Support In typescript file #27

Closed boswellgao closed 3 years ago

boswellgao commented 3 years ago

in index.tsx

import Readme from './Readme.mdx'

and the lint told me

Cannot find module './Readme.mdx' or its corresponding type declarations.ts(2307)
silvenon commented 3 years ago

Could you share more about your setup? Your Vite configuration, project structure, or ideally steps to reproduce the error.

boswellgao commented 3 years ago

@silvenon Thank you for your reply

here you can get the project

https://github.com/boswellgao/vite-react-live-preview

silvenon commented 3 years ago

The problem is with TypeScript, not vite-plugin-mdx. Vite only compiles away TypeScript, it doesn't do any type checking. One way to solve your problem is to add a common type definition for all your *.mdx files by creating a file named e.g. src/mdx.d.ts (the name doesn't matter):

declare module '*.mdx' {
  let MDXComponent: (props: Record<string, unknown>) => JSX.Element
  export default MDXComponent
}

If you need to be more specific about a particular *.mdx, add a .d.ts file with the same name.

boswellgao commented 3 years ago

@silvenon Thanks. you are right,it's typescript proplem TypeScript support for .mdx file extensions