解决Angular12报错(resize-observer-polyfill) TS2717:Property contentRect must be of type DOMRectReadOnly

左手的ㄟ右手 2023-01-22 11:50 59阅读 0赞

解决Angular12报错(resize-observer-polyfill) TS2717:Property contentRect must be of type DOMRectReadOnly

错误内容:

升级到Angular 12后,Angular UI 组件库 ng-zorro-antd 引用的 resize-observer-polyfill 库报错: Property contentRect must be of type DOMRectReadOnly, but here has type DOMRectReadOnly

具体报错如下:

  1. $ ng serve
  2. Error: node_modules/resize-observer-polyfill/src/index.d.ts:19:18 - error TS2717:
  3. Subsequent property declarations must have the same type.
  4. Property 'contentRect' must be of type 'DOMRectReadOnly', but here has type 'DOMRectReadOnly'.
  5. 19 readonly contentRect: DOMRectReadOnly;
  6. ~~~~~~~~~~~
  7. node_modules/typescript/lib/lib.dom.d.ts:12696:14
  8. 12696 readonly contentRect: DOMRectReadOnly;
  9. ~~~~~~~~~~~
  10. 'contentRect' was also declared here.

解决办法:

(1) 由于报错的是第三方类库,只能等待第三方类库去修复该错误。

(2) 在第三方修复之前,可以禁用第三方类库的检查。

在项目根目录的 TS 配置文件 tsconfig.json 中新增 skipLibCheck 属性。

  1. {
  2. "compilerOptions": {
  3. 。。。。。。
  4. "skipLibCheck": true <---- 增加该配置
  5. }
  6. }

参考链接:

https://github.com/NG-ZORRO/ng-zorro-antd/issues/6696
https://www.typescriptlang.org/tsconfig\#skipLibCheck

发表评论

表情:
评论列表 (有 0 条评论,59人围观)

还没有评论,来说两句吧...

相关阅读