mdx-js / eslint-mdx

ESLint Parser/Plugin for MDX
https://npmjs.org/eslint-plugin-mdx
MIT License
258 stars 29 forks source link

How can you type check React props with this plugin? #464

Open vb opened 1 year ago

vb commented 1 year ago

Initial checklist

Problem

I want to have a system where the author can't render a React component in mdx with the wrong props.

Example

// Component.tsx

export const Component = ({ name, age }: { name: string, age: number }) => {
  return ...
}
import { Component } from './Component'

## Component

<Component name="vb" age={35} /> // ✅
<Component name="vb" />          // ❌ Missing mandatory prop
<Component name={35} age={35} /> // ❌ Wrong type for name

Solution

I'd get an eslint error when I try to render a React component in mdx with bad props

Alternatives

I guess this is done together with plugin:@typescript-eslint?

remcohaszing commented 1 year ago

Type checking isn't done by ESLint. MDX type checking is available in MDX analyzer instead. (Though it's still early stage)

JounQin commented 11 months ago

https://github.com/ota-meshi/typescript-eslint-parser-for-extra-files

This package maybe help, I'll do some research recently.

karlhorky commented 4 months ago

Would also love if full type checking was in the toolchain somewhere - checking for the components provided through MDXProvider, as also mentioned in the mdx-analyzer discussion:

Our use case: checking whether a value of a particular slug is valid and failing CI if invalid (currently set to a union of string literals in TS):

- 🎥 slides: <LectureSlideDeck slug="js-fundamentals" />