在react-markdown中使用rehype-raw解析类型不匹配的HTML元素

问题描述 投票:0回答:1

我在我的反应项目中使用打字稿,但是当我使用this代码片段时,我收到错误

<ReactMarkdown rehypePlugins={[rehypeRaw]}>
   {content}
</ReactMarkdown>





Type '(options?: void | Options | undefined) => void | Transformer<Root, Root>' is not assignable to type 'Pluggable<any[], Settings>'.
  Type '(options?: void | Options | undefined) => void | Transformer<Root, Root>' is not assignable to type 'Plugin<any[], Settings>'.
    Type 'void | Transformer<Root, Root>' is not assignable to type 'void | Transformer'.
      Type 'Transformer<Root, Root>' is not assignable to type 'void | Transformer'.
        Type 'Transformer<Root, Root>' is not assignable to type 'Transformer'.
          Types of parameters 'node' and 'node' are incompatible.

关于该类型错误有什么想法吗?

reactjs typescript markdown react-markdown
1个回答
0
投票

我遇到了同样的错误。我通过为

as any
 添加类型断言 
rehypePlugins

来修复它
<Markdown
  rehypePlugins={[rehypeRaw] as any}
>
  {content}
</Markdown>

现在可以了。希望它也适合您。

© www.soinside.com 2019 - 2024. All rights reserved.