我在我的Typescript应用程序中使用了fabric-with-gestures,一切正常。但是,原始库fabric已经定义了类型,我可以用npm install --dev @types/fabric安装它们,但是Typescript不能识别fabric-with-gestures包中的类型。
由于没有模块@types/fabric-with-gestures,我如何将fabric中的类型与fabric-with-gestures一起使用,而且我假设这两种类型基本上是相同的?这有可能吗?
发布于 2019-11-16 02:32:44
通常,对于所有包,您可以通过向tsconfig.json添加baseUrl和paths选项来创建类型别名(我不使用fabric,但快速设置刚刚成功编译)。
tsconfig.json:
{
"compilerOptions": {
...
// absolute name imports are resolved relative to baseUrl
"baseUrl": ".",
// alias "fabric-with-gestures" is mapped to path of fabric @types
"paths": {
"fabric-with-gestures": ["node_modules/@types/fabric"]
}
}
}用法:
// Use fabric-with-gestures. Types are internally mapped to @types/fabric
import { fabric } from "fabric-with-gestures"; https://stackoverflow.com/questions/58881065
复制相似问题