我在Typescript和以下消息方面遇到问题:
{子代:Element []; pictureUrl:字符串; }'不能分配给'IntrinsicAttributes&{children ?: ReactNode; }'
属性'pictureUrl'在类型'IntrinsicAttributes&{children ?: ReactNode; }'
我真的看不到我在做什么错,有人看到了问题吗?
这是我的App组件:
import React from 'react';
import { Root, Routes, addPrefetchExcludes } from 'react-static';
import { Link, Router } from '@reach/router';
import FancyDiv from 'components/FancyDiv';
import Dynamic from 'containers/Dynamic';
import './app.css';
import NavDomicile from './components/NavDomicile';
// Any routes that start with 'dynamic' will be treated as non-static routes
addPrefetchExcludes([ 'dynamic' ]);
function App() {
return (
<Root>
<NavDomicile pictureUrl="./assets/logo-lavigo-domicile.png">
<Link to="/">Home</Link>
<Link to="/about">About</Link>
<Link to="/blog">Blog</Link>
<Link to="/dynamic">Dynamic</Link>
</NavDomicile>
<div className="content">
<FancyDiv>
<React.Suspense fallback={<em>Loading...</em>}>
<Router>
<Dynamic path="dynamic" />
<Routes path="*" />
</Router>
</React.Suspense>
</FancyDiv>
</div>
</Root>
);
}
export default App;
And My Nav Component :
<!-- begin snippet: js hide: false console: true babel: false -->
import React, { ReactNode } from 'react';
interface INavProps {
pictureUrl?: string;
children?: ReactNode;
}
const NavDomicile: React.FC = ({ children, pictureUrl }: INavProps) => {
return (
<nav>
<div>
<img src={pictureUrl} />
</div>
<div>{children}</div>
</nav>
);
};
export default NavDomicile;
答案 0 :(得分:1)
您应该为React.FC
的泛型类型提供接口
const NavDomicile: React.FC<INavProps> = ({ children, pictureUrl }) => {
}