javascript - React 组件上的打字稿错误:“元素”类型的参数不可分配给类型的参数
问题描述
我不确定它为什么在这里抱怨 TBH,这个错误让我感到困惑。
createLinkSetsForCountry
function createLinkSetsForCountry(country: Country, companies: Array<Company>) {
let companyLinks: Array<LinkItem> = [];
const companyLinkSets = [];
for (const company of companies) {
companyLinks.push(<LinkItem company={company} key={company.id} />);
companyLinkSets.push(
<LinkSet
className="ft-link-set"
country={country}
key={company.id}
links={companyLinks} />
);
companyLinks = [];
}
return (
<div>
<ListHeader country={country} />
<div>{companyLinkSets}</div>
</div>
);
}
链接项
export class LinkItem extends Component<{ company: Company, key: number }> {
render() {
const { company } = this.props,
hasApp = (company.interview
&& company.interview.app
&& company.interview.app.hasAppp),
uri = company.notInterviewed ? `companies/${company.id}/details` : `/interviews/companies/${company.id}`,
className = `margin-top-10 margin-bottom-10 ${
company.notInterviewed ? 'ft-company-not-interviewed' : ''
}`;
const link = (
<Link className={className} id={company.id.toString()} to={uri}>
<span id="company-name">{company.name}</span>
</Link>
);
return (
<div className="company-link vertical-align-top inline-block">
<div>
<li className="margin-0">{link}</li>
</div>
{hasApprenticeship && (
<div className="align-center ft-tags margin-0" id="tags">
<span
className="ink-tooltip ink-badge category-badge font-9 inline ft-apprenticeship-tag"
data-tip-color="tooltip"
data-tip-text="offers dddd"
data-tip-where="up">
A
</span>
</div>
)}
</div>
);
}
}
解决方案
基本上,您companyLinks
是 React 元素的列表而不是LinkItem
,因此只需更改以下内容即可:
let companyLinks: Array<React.ReactElement> = [];
推荐阅读
- uwsgi - 如何在 500 响应中制作瓶子打印错误消息?
- javascript - Masonry 仅在调整浏览器大小时有效
- javascript - 复制功能实现
- r - 更改数据框列表上的日期
- typescript - 使用 ts-checker-webpack-plugin 时 tslint 找不到用 TypeScript 编写的自定义 tslint 规则
- python - 从文件的开头和结尾删除行并将剩余的行写入新文件
- javascript - 如何在javascript中放置链接
- node.js - 如何在异步等待调用节点上设置超时
- swagger - 如何表示无关的 Swagger 参数
- ms-access - VBA DSum 在访问中不起作用