Skip to content
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

Typescript error while using syntax hightlight part code from README.md #826

Closed
4 tasks done
18601673727 opened this issue May 3, 2024 · 4 comments
Closed
4 tasks done
Labels
👯 no/duplicate Déjà vu 👎 phase/no Post cannot or will not be acted on

Comments

@18601673727
Copy link

Initial checklist

Affected packages and versions

latest

Link to runnable example

No response

Steps to reproduce

I'm using like this,

<Markdown
  remarkPlugins={[remarkBreaks, remarkGfm]}
  components={{
    code({ children, className, node, ...rest }) {
      const match = /language-(\w+)/.exec(className || "");
      return match ? (
        <SyntaxHighlighter
          {...rest}
          PreTag="div"
          children={String(children).replace(/\n$/, "")}
          language={match[1]}
          style={theme === DEFAULT_THEME ? twilight : xonokai}
        />
      ) : (
        <code {...rest} className={className}>
          {children}
        </code>
      );
    },
  }}
>
  {input}
</Markdown>

It will cause VSCode to complain about types error,

No overload matches this call.
  Overload 1 of 2, '(props: SyntaxHighlighterProps): SyntaxHighlighter', gave the following error.
    Type '{ PreTag: "div"; children: string; language: string; style: { [key: string]: CSSProperties; }; ref?: LegacyRef<HTMLElement> | undefined; key?: Key | null | undefined; ... 267 more ...; onTransitionStartCapture?: TransitionEventHandler<...> | undefined; }' is not assignable to type 'IntrinsicClassAttributes<SyntaxHighlighter>'.
      Types of property 'ref' are incompatible.

then I made following change:

-  code({ children, className, node, ...rest }) {
+  code({ children, className, node, ref, ...rest }) { 

Problem solved, so maybe it was kinda useful to note this here. and feel free to close anytime.

Expected behavior

Everything works

Actual behavior

No overload matches this call.
  Overload 1 of 2, '(props: SyntaxHighlighterProps): SyntaxHighlighter', gave the following error.
    Type '{ PreTag: "div"; children: string; language: string; style: { [key: string]: CSSProperties; }; ref?: LegacyRef<HTMLElement> | undefined; key?: Key | null | undefined; ... 267 more ...; onTransitionStartCapture?: TransitionEventHandler<...> | undefined; }' is not assignable to type 'IntrinsicClassAttributes<SyntaxHighlighter>'.
      Types of property 'ref' are incompatible.

Runtime

No response

Package manager

No response

OS

No response

Build and bundle tools

No response

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels May 3, 2024
Copy link

github-actions bot commented May 3, 2024

Hi! Thanks for taking the time to contribute!

Because we treat issues as our backlog, we close duplicates to focus our work and not have to touch the same chunk of code for the same reason multiple times. This is also why we may mark something as duplicate that isn’t an exact duplicate but is closely related.

Thanks,
— bb

@ChristianMurphy
Copy link
Member

Duplicate of #666

@ChristianMurphy ChristianMurphy marked this as a duplicate of #666 May 3, 2024
@ChristianMurphy ChristianMurphy closed this as not planned Won't fix, can't repro, duplicate, stale May 3, 2024

This comment has been minimized.

@ChristianMurphy
Copy link
Member

See the answer in #666 (comment)

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👯 no/duplicate Déjà vu 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants