question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript support for .mdx file extensions

See original GitHub issue

Search Terms

  • .mdx
  • mdx
  • mdx support

Suggestion

Could or would it be on the road map to allow type checking in non .ts files. In my case i’m specifically wondering if TypeScript can type check React components in .mdx files

Use Cases

I’ve written a gatsby plugin gatsby-mdx-embed that allows users to embed media content from YouTube, Twitter, Instagram etc in their .mdx files.

The plugin is written in TypeScript and all of the components have props. It would be sweet if when these components are used in .mdx files a user could either see the prop types by hovering over the component or more importantly would get a type error (squiggly line) in their code editor if the prop name is incorrect or of incorrect type.

Examples

Here’s an example .mdx file

You can below there the Gist component accepts a gistLink prop of type string.

<Playground>
  <Gist gistLink="PaulieScanlon/ca0cc9239176066492cb2aba435edbf7" />
</Playground>

If a user misspelled gistLink or provided a number / array or object etc the editor would alert them there’s been an error in the prop type used.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:163
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

59reactions
Peejacommented, Mar 13, 2020

Similarly, when writing Storybook stories in MDX, it would be a big help to have TypeScript understand them. Stories are a kind of test, and not type-checking tests is a scary prospect.

21reactions
kyleknightedcommented, Mar 2, 2022

I stumbled across this Issue while searching for type checking Storybook. And, while I haven’t tried it yet, I did see that @Yama-Tomo is working on this in https://github.com/Yama-Tomo/type-checking-MDX-in-storybook

Figured I would share it here incase anyone else is interested!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript
If you're getting errors from TypeScript related to imports with an *.mdx extension, create an mdx.d.ts file in your types directory and include...
Read more >
Typescript show error for .mdx extension file in nextjs
It work fine for render component to website but typescript show error for import mdx file. typescript error message: Cannot find module '@/ ......
Read more >
What's new in MDX v2
The improved MDX architecture also comes with TypeScript support. According to the MDX team,. All @mdx-js/* packages are now fully typed with ...
Read more >
mdx-js/mdx
TypeScript icon, indicating that this package has built-in type ... Format the file is in ( 'detect' | 'mdx' | 'md' , default:...
Read more >
Prettier 2.5: TypeScript 4.5 and MDX v2 comment syntax!
Prettier will now format files with .mts and .cts extensions as TypeScript. HTML. Collapse HTML class attributes onto ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found