TS2532: Object is possibly ‘undefined’,提示对象可能未定义,但其实是有值的,页面也能正常显示,但是对于我来说,看见报错爆红实在无法忍受

解决方法:在后面使用!非空运算符;也就是在后面加上感叹号( ! );让编译器知道不会未定义或成为null

 想了解多种解决方法,可查看:

How to solve TypeScript possibly undefined valueThis article goes over 5 methods to solve a problem like TS2532: Object is possibly ‘undefined’. You can use IF conditions, logical operator, non-null assertion and more. https://linguinecode.com/post/how-to-solve-typescript-possibly-undefined-value

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐