使用TypeScript开发React项目,开发中用Map循环渲染UI时,出现这个错误是因为Typescript在执行代码检查时在该对象没有定义相应属性,遇到该错误有以下几种解决办法。

  • 将对象设置成 any类型

    <ul>{data.hits.map((item: any) => (<li key={item.objectID}><a href={item.url}>{item.title}</a></li>))}
    </ul>
    
  • 通过字符方式获取对象属性

    <ul>{data.hits.map(item => (<li key={item['objectID']}><a href={item['url']}>{item['title']}</a></li>))}
    </ul>
    
  • 声明断言,强制执行

    
    
  • List item

    • {data.hits.map(item => (

TypeScript Property ‘XXX‘ does not exist on type ‘never‘相关推荐

  1. TypeScript Property ‘XXX‘ does not exist on type ‘never‘.

    开发过程中出现这个错误是因为Typescript在执行代码检查时在该对象没有定义相应属性,这个错误不致命,遇到该错误有以下几种解决办法. 1,将对象设置成 any this.targetArray = ...

  2. property xxx does not exist on type Object报错

    在TypeScript中如果按JS的方式去获取对象属性,有时会提示形如Property 'xxx' does not exist on type 'Object'的错误.下文代码中的'xxx'替换成你 ...

  3. 完美解决:Property ‘XXX‘ does not exist on type ‘Window‘

    发生情景: 在app中的h5,app注入了全局的window对象和webview里面的页面交互,打包的时候报了错误. 解决方式: 方法一: (window as any).xxx 方法二: decla ...

  4. Property ‘xxx‘ does not exist on type ‘{ xxx(file: any, fileList: any): void;的报错

    关闭tsconfig.json里的"strict",把 true 改为 false 即可

  5. 响应式编程时出现:error TS2339: Property 'debounceTime' does not exist on type 'Observableany'.

    constructor() {this.searchInput.valueChanges//.debounceTime(500) 无法使用.pipe(debounceTime(1000)).subsc ...

  6. Angular响应式开发中报错Property 'map' does not exist on type 'Observable'.引用rxjs也没用。

    Angular响应式开发源代码如下: import { Component, OnInit } from '@angular/core'; import {Observable} from 'rxjs ...

  7. Property ‘next‘ does not exist on type ‘Component<any, {}, any>‘问题的解决方法

    场景:使用antd的Carousel组件时,自定义左右切换按钮,触发组件的next(),prev()方法时报错 错误写法: handleNext(){this.refs.img.next()}< ...

  8. TS2550: Property ‘entries‘ does not exist on type ‘ObjectConstructor‘.

    问题:TS2550: Property 'entries' does not exist on type 'ObjectConstructor'. Do you need to change your ...

  9. Property ‘contentWindow‘ does not exist on type HTMLElement,类型htmlelement上不存在contentwindow属性

    一.问题 Property 'contentWindow' does not exist on type HTMLElement 二.解决方法 /*** Property 'contentWindow ...

  10. Property ngOnInit does not exist on type VisibleFocusDirective

    原因是我把Base focus Directive的OnInit函数删除了: 添加上之后问题消失: 更多Jerry的原创文章,尽在:"汪子熙":

最新文章

  1. VC++ _T()宏学习
  2. 自动驾驶「无视」障碍物:百度研究人员攻陷激光雷达
  3. java.util.ConcurrentModificationException
  4. 强健程序员体魄————减脂原理
  5. Flutter ScrollController not attached to any scroll views 异常
  6. php get教程,PHP $_GET 变量
  7. angular引用bootstrap_angular怎么引入bootstrap?
  8. 36 岁程序员应聘被公司领导直接拒绝;字节跳动:公司暂不具备上市条件;财务软件 bug 致数百人被错误定罪|极客头条...
  9. Luogu P4403 [BJWC2008]秦腾与教学评估【二分答案】By cellur925
  10. 阶段3 1.Mybatis_09.Mybatis的多表操作_6 分析mybatis多对多的步骤并搭建环境
  11. express不是内部或外部命令的解决方法
  12. HDU3364 Lanterns
  13. 【Nginx】Nginx 工作原理
  14. AD9 PCB文件黑色区域如何改变?
  15. Linux中cinder的作用,11-cinder块存储服务部署
  16. base64格式转换成普通png格式
  17. 教你免费使用百度云GPU算力提交深度学习任务
  18. win7与internet时间同步出错_win7系统时间不同步怎么办|win7系统时间同步出错的解决方法...
  19. 英伟达A100 Tensor Core GPU架构深度讲解
  20. 手持弹幕android制作,手持弹幕神器

热门文章

  1. 云服务总线CSB:“连”无边界
  2. 家庭作业 题解(C++)
  3. 还记得最初的九九乘法表吗?
  4. QGC 谷歌中国地图 火星坐标系 转换
  5. 王者荣耀战力查询微信小程序源码下载支持安卓苹果微信Q等多区查询
  6. [转载]只因写了一段爬虫,公司200多人被抓!
  7. 大学计算机课程进制的转换教程,交大计算机课程(1):各种进制转换
  8. 详解百度快照劫持,小白必看篇
  9. M个苹果放在N个盘子里,有多少种不同的放法
  10. Oracle视图(View)----------------数据库中虚拟的表