nextjs- typescript- 类型“IntrinsicAttributes 和 IntrinsicClassAttributes”上不存在属性“className”

Nik*_*hil 5 typescript reactjs next.js

我已经使用 typescript 链接创建了基本的 nextjs 应用程序 - https://github.com/zeit/next.js/tree/master/examples/with-typescript

我无法将 className 属性添加到任何元素。我收到以下错误。属性 'className' 不存在于类型 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode; }>

我也收到其他属性的类型错误,例如链接元素上的 rel。

Head > 链接属性的错误

错误 2 类型检查错误

Dmi*_*try 4

请参阅 NextJS文档。Link 不是 DOM 元素,因此您需要将 className 直接添加到<a>标记中,而不是添加到<Link>.

文档中的基本示例:

// pages/index.js
import Link from 'next/link'

function Home() {
  return (
    <>
      <ul>
        <li>Home</li>
        <li>
          <Link href="/about">
            <a>About Us</a>
          </Link>
        </li>
      </ul>
    </>
  )
}

export default Home
Run Code Online (Sandbox Code Playgroud)

  • 点评来源: 你好,虽然链接是分享知识的好方法,但如果将来它们被破坏,它们将无法真正回答问题。将回答问题的链接的基本内容添加到您的答案中。如果内容太复杂或太大而无法放在这里,请描述所提出的解决方案的总体思路。请记住始终保留原始解决方案网站的链接引用。请参阅:[如何写出一个好的答案?](https://stackoverflow.com/help/how-to-answer) (2认同)