Skip to content

How to properly type pre components? #1264

Discussion options

You must be logged in to vote

Welcome @Californian! 👋

How to properly type pre components?

As @wooorm mentions JSX.IntrinsicElements['pre'] & ExtraProps is the correct type

Typescript complains that Property 'props' does not exist on type 'ReactNode'., but everything works as expected and, indeed, there is a property props on the children. Perhaps children needs to be typed differently?

TypeScript is correct, props is not guaranteed to be on children.
children could also be null, a string, or a list of elements.
You happen to have props on the documents you have tested, but don't rely on that assumption.
Instead consider something like:

import { isValidElement } from "react";

// ...

<ReactMarkdown
  components={{

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Californian
Comment options

@ChristianMurphy
Comment options

@Californian
Comment options

Answer selected by Californian
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants