【发布时间】:2017-11-08 13:11:42
【问题描述】:
我正在使用包@types/cropperjs
不幸的是,它落后于当前的cropper.js 版本并且缺少scale 方法。
到目前为止,我只是手动将缺失的方法添加到 node_modules 下的 d.ts 文件中(这显然是个坏主意,所以不要这样做!这只是一个临时修复)
我尝试将来自 node_modules 的定义与我自己的声明合并。
declare class cropperjs {
/**
* Scale the image.
*
* @param scaleX The scaling factor to apply on the abscissa of the image.
* When equal to 1 it does nothing. Default is 1
* @param scaleY The scaling factor to apply on the ordinate of the image.
* If not present, its default value is scaleX.
*/
scale(scaleX: number, scaleY?: number): void;
}
export = cropperjs;
export as namespace Cropper;
来自 DefinitlyTyped 存储库的类型可以是 found on github(看起来很相似,但太大而无法在此处显示)
以下是我在角度组件中导入cropper 的方法。
import * as Cropper from 'cropperjs';
这是我的 tsconfig.json(部分内容)
"typeRoots": [
"node_modules/@types",
"node_modules/@angular",
"src/typings"
],
"types": [
"jasmine",
"node",
"karma",
"webpack",
"cropperjs"
]
我用我的自定义类型文件夹和三斜杠引用符号尝试了它。 但我不知道如何成功合并我的定义和 DefinitlyTyped 的定义,这样我就可以使用cropperjs 而不必在 node_module 中摆弄
附: 我已经在 github 上打开了更新定义的问题(没有拉取请求,因为当时几乎不了解 git)。
【问题讨论】:
标签: angular typescript typescript-typings