-
-
Notifications
You must be signed in to change notification settings - Fork 874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError when using react-syntax-highlighter #666
Comments
@Katsukiniwa thanks for reaching out, sorry you ran into a spot of trouble. see https://codesandbox.io/s/react-markdown-syntax-highlight-typescript-p9tw0 for an example, try adding and removing code({ node, inline, className, children, ref, ...props }) {
^^^^ full exampleimport React from "react";
import Markdown from "react-markdown";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { darcula } from "react-syntax-highlighter/dist/cjs/styles/prism";
const markdownSource = `
# heading
* list
* items
\`\`\`js
function () {}
\`\`\`
`;
const App = () => (
<Markdown
components={{
code({ node, inline, className, children, ref, ...props }) {
const match = /language-(\w+)/.exec(className || "");
return !inline && match ? (
<SyntaxHighlighter style={darcula} language={match[1]} {...props}>
{String(children).replace(/\n$/, "")}
</SyntaxHighlighter>
) : (
<code className={className}>{children}</code>
);
}
}}
>
{markdownSource}
</Markdown>
);
export default App;
```
</details> |
@ChristianMurphy https://github.com/remarkjs/react-markdown#use-custom-components-syntax-highlight |
The example in the readme is JavaScript. Thoughts @wooorm or @remcohaszing on changing the example to TS? 💭 |
I think this could be a bug in On the following lines react-markdown/lib/ast-to-react.js Lines 52 to 58 in 9a25ef8
This is correct if /**
* @typedef {React.ComponentPropsWithoutRef<'code'> & ReactMarkdownProps & {inline?: boolean}} CodeProps
*/ |
It is rendered here: react-markdown/lib/ast-to-react.js Lines 316 to 319 in 9a25ef8
and is reflecting the intrinsic type here: react-markdown/lib/complex-types.ts Lines 24 to 28 in 9a25ef8
and I correct in interpreting your comment to mean // in react-markdown/lib/complex-types.ts line 27
JSX.IntrinsicElements[TagName]
// could be replaced with
React.ComponentPropsWithoutRef<TagName> ? |
That seems correct more than the types I referenced, but indeed the problem is what I suspected: |
@Katsukiniwa you could also give version 7.1.2 a try, it should not require any tinkering with |
@ChristianMurphy |
If I'm reading this issue correctly, at this momenet, on version 9.0.0, the same problem is still there and |
Hey again @18601673727! 👋 And the compatability issue in the types was from several react versions ago, you are seeing something something relayed but different. Likely you are using an incompatible version of the react types. Version 18 is currently supported. Line 96 in 78160f5
|
Hello @ChristianMurphy, sorry being so blunt about it, but my current package.json is here:
I know all this open sourced "compiler work" weights a lot, and maintainers like you deserve huge amount of respect, but we all know that it's 2024 already and typescript is more or less a default kind of thing to README.md about, upstream issue happens but considering the user base |
While I like and use TypeScript, I respectfully disagree.
The third, and best option, is to look into the root of the problem, and open a fix to
No "but". Take the time to frame your problem https://github.com/remarkjs/.github/blob/main/support.md, share a runnable example of the issue you are seeing (https://stackblitz.com/github/remarkjs/.github/tree/main/sandbox-templates/react-markdown-with-vite is good starting point), and consider the alternatives. |
Are you saying |
Nowhere did I say that, making things up just to argue will get you blocked from the community.
Share a reproducible example of what you are seeing as I asked you to above, and we can find out together.
Likely, right now you seem to be both.
I'm not willing to risk breaking code or misleading 12k+ people because one angry commenter, who refuses give an example of what they are seeing, disagrees with part of the documentation. |
@18601673727 you are embarrassing yourself. This is issues. You are commenting on other people's issues and picking fights. Last warning. Be constructive and follow orders or be blocked. |
Initial checklist
Affected packages and versions
7.1.1
Link to runnable example
No response
Steps to reproduce
type error happened.
Expected behavior
props.ref type should be
LegacyRef<SyntaxHighlighter> | undefined
Actual behavior
no error found.
Runtime
Node v16
Package manager
No response
OS
macOS
Build and bundle tools
Next.js
The text was updated successfully, but these errors were encountered: