TypeScript Property ‘XXX‘ does not exist on type ‘never‘
使用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‘相关推荐
- TypeScript Property ‘XXX‘ does not exist on type ‘never‘.
开发过程中出现这个错误是因为Typescript在执行代码检查时在该对象没有定义相应属性,这个错误不致命,遇到该错误有以下几种解决办法. 1,将对象设置成 any this.targetArray = ...
- property xxx does not exist on type Object报错
在TypeScript中如果按JS的方式去获取对象属性,有时会提示形如Property 'xxx' does not exist on type 'Object'的错误.下文代码中的'xxx'替换成你 ...
- 完美解决:Property ‘XXX‘ does not exist on type ‘Window‘
发生情景: 在app中的h5,app注入了全局的window对象和webview里面的页面交互,打包的时候报了错误. 解决方式: 方法一: (window as any).xxx 方法二: decla ...
- Property ‘xxx‘ does not exist on type ‘{ xxx(file: any, fileList: any): void;的报错
关闭tsconfig.json里的"strict",把 true 改为 false 即可
- 响应式编程时出现:error TS2339: Property 'debounceTime' does not exist on type 'Observableany'.
constructor() {this.searchInput.valueChanges//.debounceTime(500) 无法使用.pipe(debounceTime(1000)).subsc ...
- Angular响应式开发中报错Property 'map' does not exist on type 'Observable'.引用rxjs也没用。
Angular响应式开发源代码如下: import { Component, OnInit } from '@angular/core'; import {Observable} from 'rxjs ...
- Property ‘next‘ does not exist on type ‘Component<any, {}, any>‘问题的解决方法
场景:使用antd的Carousel组件时,自定义左右切换按钮,触发组件的next(),prev()方法时报错 错误写法: handleNext(){this.refs.img.next()}< ...
- TS2550: Property ‘entries‘ does not exist on type ‘ObjectConstructor‘.
问题:TS2550: Property 'entries' does not exist on type 'ObjectConstructor'. Do you need to change your ...
- Property ‘contentWindow‘ does not exist on type HTMLElement,类型htmlelement上不存在contentwindow属性
一.问题 Property 'contentWindow' does not exist on type HTMLElement 二.解决方法 /*** Property 'contentWindow ...
- Property ngOnInit does not exist on type VisibleFocusDirective
原因是我把Base focus Directive的OnInit函数删除了: 添加上之后问题消失: 更多Jerry的原创文章,尽在:"汪子熙":
最新文章
- VC++ _T()宏学习
- 自动驾驶「无视」障碍物:百度研究人员攻陷激光雷达
- java.util.ConcurrentModificationException
- 强健程序员体魄————减脂原理
- Flutter ScrollController not attached to any scroll views 异常
- php get教程,PHP $_GET 变量
- angular引用bootstrap_angular怎么引入bootstrap?
- 36 岁程序员应聘被公司领导直接拒绝;字节跳动:公司暂不具备上市条件;财务软件 bug 致数百人被错误定罪|极客头条...
- Luogu P4403 [BJWC2008]秦腾与教学评估【二分答案】By cellur925
- 阶段3 1.Mybatis_09.Mybatis的多表操作_6 分析mybatis多对多的步骤并搭建环境
- express不是内部或外部命令的解决方法
- HDU3364 Lanterns
- 【Nginx】Nginx 工作原理
- AD9 PCB文件黑色区域如何改变?
- Linux中cinder的作用,11-cinder块存储服务部署
- base64格式转换成普通png格式
- 教你免费使用百度云GPU算力提交深度学习任务
- win7与internet时间同步出错_win7系统时间不同步怎么办|win7系统时间同步出错的解决方法...
- 英伟达A100 Tensor Core GPU架构深度讲解
- 手持弹幕android制作,手持弹幕神器