关于在vue3 reactive中使用TypeScript时,出现’state’ implicitly has type ‘any’ because it does not have a type annotation and is referenced directly or indirectly in its own initializer.报错。


关于这个错误的解释是:

state”隐式具有类型“any”,因为它没有类型注释并且在其自己的初始化程序中直接或间接引用

解决方案

出现这个问题时由于TypeScript里自带的类型检测,导致编译报错,但实际并不影响程序是使用,毕竟他在js中是完全可行的。

这个解决方法是用了TypeScript中的类型断言,通过类型断言这种方式可以告诉编译器,“相信我,我知道自己在干什么”类型断言好比其它语言里的类型转换,但是不进行特殊的数据检查和解构。 它没有运行时的影响,只是在编译阶段起作用。 TypeScript会假设你,程序员,已经进行了必须的检查。
简言之,你(编译器)别问我(程序)了,我知道自己在干什么。

it does not have a type annotation and is referenced directly or indirectly in its own initializer相关推荐

  1. Type string trivially inferred from a string literal, remove type annotation.eslint@typescript-eslin

    TypeScript代码类似: const web: string = "Hello World"; 如果是用eslint 验证会导致报错 Type string triviall ...

  2. Type string trivially inferred from a string literal, remove type annotation

    Angular报错:Type string trivially inferred from a string literal, remove type annotation stockCode: st ...

  3. Java Type Annotation

    在 Java 8 之前的版本中,只能允许在声明式前使用 Annotation.而在 Java 8 版本中,Annotation 可以被用在任何使用 Type 的地方,例如:初始化对象时 (new),对 ...

  4. the type xxx cannot be resoved,It is indirectly referenced from required .class files错误.....

    在Eclipse中遇到The type XXX cannot be resolved. It is indirectly referenced from required .class files错误 ...

  5. The type XXX cannot be resolved. It is indirectly referenced from required .class files错误.....

    遇到The type XXX cannot be resolved. It is indirectly referenced from required .class files错误.....,查找的 ...

  6. Type number trivially inferred from a number literal, remove type annotation.

    错误场景: vue3 使用 typescript 图片示例: typescript 对代码做了类型推断,num2 不需要再指明number类型. 解决办法一. const num2 = 11 解决办法 ...

  7. typescript ts 错误列表

    code 类型 英文描述 中文描述 1002 错误 Unterminated string literal. 未终止的字符串文本. 1003 错误 Identifier expected. 应为标识符 ...

  8. typescript TS 错误码大全

    code    类型    英文描述    中文描述 1002    错误    Unterminated string literal.    未终止的字符串文本. 1003    错误    Id ...

  9. typescript 错误码大全

    转载于https://www.easemob.com/question/6196/ 1002 错误 Unterminated string literal. 未终止的字符串文本. 1003 错误 Id ...

最新文章

  1. Recordset.State 属性
  2. VC++2012编程演练数据结构《12》二叉排序树
  3. 将Markdown嵌入到我们的HTML页面中
  4. hashchange
  5. adb命令启动activity、service,发送broadcast
  6. linux下查看pck设备,Linux中查看硬件信息超强命令sar
  7. 大道至简第二章-‘是懒人造就了方法’读后感
  8. Beginning Python chapter 1 Instant Hacking The Basics 2: Comments Strings
  9. 【14浙江省赛 B ZOJ 3777】Problem Arrangement 【状压dp】 【CCPC-Wannafly Winter Camp Day2 K Sticks】
  10. js写用户名密码错误提示_写给前端的 Jenkins 教程——快速实现前端/ Node.js 项目的 CI/CD...
  11. C语言10个经典小程序——小白必备!
  12. WebLogic的下载和安装
  13. 【ELM预测】基于蝴蝶算法优化极限学习机预测附matlab代码
  14. 在这领工资,一辈子别想取媳妇了!
  15. 小程序源码图片列表,图片下载
  16. UUI Make StartUp Disk
  17. VI/VIM 编辑器
  18. 每天进步一点点【稀疏数组】
  19. 网页如何旋转90度?
  20. android paint的抗锯齿效果

热门文章

  1. Mysql 安装 000007b_Win7安装软件出现应用程序无法正常启动0xc000007b的提示怎么解决...
  2. #define定义宏常量和宏函数
  3. 总谐波失真加噪声(THD+N)
  4. 【小技巧】argc和argv的用法
  5. Anniversary party(最基础的树形dp)
  6. 关于PKI 你了解多少
  7. QT - 创建UDP Socket通信
  8. 什么是JavaBean、bean? 什么是POJO、PO、DTO、VO、BO ? 什么是EJB、EntityBean?
  9. 统计学中基础概念说明
  10. Sprint(第二天11.15)