我使用包@types/cropperjs
不幸的是,它落後於當前的cropper.js版本,缺少方法scale
。 到目前爲止,我只是手動添加缺少的方法將d.ts下node_modules文件(這顯然是一個壞主意,所以不要做!這只是一個臨時的。修復)添加類型缺少的方法(從一個NPM包)
我試着將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(它看起來類似,但太大了,這裏顯示)
以下是我在一個角度成分導入農作物。
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四處亂動
P.S. 我已經在github上更新了定義(沒有拉請求,因爲當時幾乎沒有git的知識)已經打開了一個問題。