我目前正在将 Next.js 项目从 JavaScript 迁移到 TypeScript,但遇到了错误:Property 'className' does not exist on type '{ props: ReactNode; }'。在 Javascript 中,我可以从 props 中提取 className,但打字稿找不到类型。这是代码:
import { useRouter } from 'next/router'
import Link from 'next/link'
import { ReactNode } from 'react'
export { NavLink }
NavLink.defaultProps = {
exact: false,
}
interface NavLinkProps {
href: string
exact?: boolean
children: ReactNode
props: ReactNode
}
function NavLink({ href, exact, children, ...props }: NavLinkProps) {
const { pathname } = useRouter()
const isActive = exact …Run Code Online (Sandbox Code Playgroud)