1

我遇到了 Typescript 和以下消息的问题:

{孩子:元素[];图片网址:字符串;}' 不可分配给类型 'IntrinsicAttributes & { children?: ReactNode; }'

类型“IntrinsicAttributes & { children?: ReactNode;”上不存在属性“pictureUrl” }'

我真的不明白我做错了什么,有人看到问题了吗?

这是我的应用程序组件:

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;

4

1 回答 1

2

您应该为类型泛型提供接口React.FC

const NavDomicile: React.FC<INavProps> = ({ children, pictureUrl }) => {


}
于 2020-05-09T17:50:29.173 回答