我正在使用 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;
....
接下来就可以了,因为它匹配 d.ts 定义:
// Override fabric to meet ourrequirements
fabric.util.object.extend(fabric.Object.prototype, {
centeredRotation: true,
如何忽略
DPI
TS2339 错误。拥有自动完成功能真的很棒,特别是对于学习 Fabric 。 我的 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 的解决方案。
通过改变这个:
import * as fabric from 'fabric/fabric-impl';
到 import { fabric } from 'fabric';
我现在也启用了 VisualStudio 智能感知。当然,我在 package.json 中添加了 @types/fabricjs。最佳答案
例如像这样 (fabric as any).DPI = 213;
关于angular - 如何忽略 TypeScript 错误 TS2339 - 类型上不存在属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59631075/