打字稿定义混乱

时间:2015-05-20 06:37:00

标签: javascript typescript definition

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

/// <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/

我做错了什么?

1 个答案:

答案 0 :(得分:1)

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

修复:您的定义应该是

interface ColorThief{
  new ():any;
}
相关问题