打字稿定义混乱

苍鹭

这就是我的打字稿文件的样子。

/// <reference path="../typings/jquery/jquery.d.ts" />

interface JQuery {
    ColorThief:any;
}

class Color {
    isItDarkColor(rgb) {
        var rgbColors = rgb.toString().split(","),
            r = parseFloat(rgbColors[0]),
            g = parseFloat(rgbColors[1]),
            b = parseFloat(rgbColors[2]);
        var percentage = Math.sqrt(
                r * r * 0.299 +
                g * g * 0.587 +
                b * b * 0.114
            ) / 2.55;
        return (percentage < 70);
    }

    getColor(src) {
        var image = new Image,
            colorThief = new ColorThief();
        image.src = src;
        return colorThief.getColor(image);
    }
}

在编译过程中出现错误信息

Cannot find name 'ColorThief'.

这是我要使用的彩色小偷插件,它已经包含在html标记中

https://github.com/lokesh/color-thief/

我究竟做错了什么?

巴萨拉特

您将其定义为一个,jquery plugin但是实际上它只是一个JavaScript类

修复:您的定义应类似于

interface ColorThief{
  new ():any;
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章