reactjs - 离子反应,正确代码的错误“类型参数不可分配”
问题描述
我有一些错误信息。对于排除代码问题,我在标准应用程序中发现了此错误。当我使用“空白”、“侧边菜单”、“标签”时,一切正常。但是当开始“会议”然后运行时,我有错误消息:
/home/stdt/src/components/Map.tsx(15,39) 中的 TypeScript 错误:
[react-scripts] 类型参数 'HTMLDivElement | null' 不可分配给“元素”类型的参数。[react-scripts] 类型“null”不可分配给类型“元素”。TS2345 [反应脚本]
13 | useEffect(() => { [react-scripts]
14 | [react-scripts]
15 | map.current = new google.maps.Map(mapEle.current, { [react-scripts] ^
其他一些应用程序中的类似问题。此代码来自示例,因此没有代码问题。我应该怎么做,安装一些东西或别的东西?
解决方案
我曾经也有过一样的问题。我发现的两个“解决方案”是:
- 在 tsconfig.json 中添加一行:
"strictNullChecks": false,
- 在 src/components/Map.tsx 地方
if (mapEle && mapEle.current) {
和}
周围使用 mapEle:
if (mapEle && mapEle.current) {
map.current = new google.maps.Map(mapEle.current, {
center: {
lat: mapCenter.lat,
lng: mapCenter.lng
},
zoom: 16
});
addMarkers();
google.maps.event.addListenerOnce(map.current, 'idle', () => {
if (mapEle.current) {
mapEle.current.classList.add('show-map');
}
});
}
推荐阅读
- statistics - 三向交互效应的非参数检验
- docker - 在 Windows 容器中,服务会自动停止
- javascript - 我没有在 HTML 文件中添加脚本,但是 react 应用程序仍然可以工作,怎么样?
- python - 使用带有条件的 value_counts(日期时间)
- json - 如何搜索仅在彼此之后出现的两个字符串?
- azure - Terraform:错误:解析应用服务资源 ID 时出错
- reactjs - 获取中的正确 CORS 标头做出反应
- sql - Query Multiplies The Result When Selecting For One Value
- c# - How to continuously send a network stream in c#
- node.js - Outside function not calling in lambda node js exports.handler?