Skip to content
Discussion options

You must be logged in to vote

TypeScript is alerting you that you've implicitly typed className as required, but it is optional.
There are two ways you could go about resolving this, both involve more explicitly typing.
The first, move components inline

<ReactMarkdown children={body} components={ components: {
  code({node, inline, className, children, ...props}) {
    const match = /language-(\w+)/.exec(className || '')
    return !inline && match ? (
      <SyntaxHighlighter style={dark} language={match[1]} PreTag="div" children={String(children).replace(/\n$/, '')} {...props} />
    ) : (
      <code className={className} {...props} />
    )
  }
} } />

this allows typescript to use ReactMarkdown's types directly.

T…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@s7tya
Comment options

Answer selected by ChristianMurphy
Comment options

You must be logged in to vote
1 reply
@nkhil
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
☂️ area/types This affects typings
5 participants