angular - 如何忽略 TypeScript 错误 TS2339 - 类型上不存在属性
问题描述
我正在使用 Angular 8(在 Visual Studio 2019 中启动了一个项目)并拥有fabric.init.ts
包含下一个内容的文件:
import 'fabric';
import * as fabric from 'fabric/fabric-impl';
// (TS) Property 'DPI' does not exist on type 'typeof import(..@types/fabric/fabric-impl)'
fabric.DPI = 213;
....
Next 没问题,因为它符合 d.ts 定义:
// Override fabric to meet ourrequirements
fabric.util.object.extend(fabric.Object.prototype, {
centeredRotation: true,
如何忽略DPI
TS2339 错误。拥有自动补全功能真的很棒,特别是对于学习结构。
我的 package.json:
"private": true,
"dependencies": {
"@angular/core": "8.2.14",
....
"@angular/router": "8.2.14",
"@types/fabric": "3.5.1",
"fabric": "3.5.1",
...
},
编辑
现在我通过添加这一行来解决它:
// @ts-ignore
fabric.DPI = 213;
我知道这不是最好的解决方案,我更喜欢@wentjun 的解决方案。
通过改变这个:我现在也启用了 VisualStudio 智能感知import * as fabric from 'fabric/fabric-impl';
。import { fabric } from 'fabric';
当然,我在 package.json 中添加了@types/fabricjs。
解决方案
比如像这样(fabric as any).DPI = 213;
推荐阅读
- typescript - 枚举参数类型的简写
- python - python为什么我不断从select.select中得到ValueError:文件描述符不能是负整数(-1)
- asp.net-mvc-5 - mvc 5 项目我收到此错误:mscorlib.dll 中出现“System.Data.SqlClient.SqlException”类型的异常
- flutter - 我无法在 Dart 中将父类转换为其子类
- javascript - 可以根据子页面将 id 添加到 iframe 的父级吗?
- c++ - 我如何一般地传递 TForm (this)?
- azure - 如何从 Spring Cloud 功能发回自定义 http 响应代码?
- arrays - 如何使用循环填充和排列
- amazon-web-services - 是否可以按您不想要的名称过滤 aws_ami 中的 AMI
- python - matplotlib 动画看起来与序列化的 imshow 不同