2015-05-20 85 views
0

这是我的打字稿文件的样子。手稿定义混淆

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

什么时我做错了?

+0

你不应该用'新jQuery.ColorThief'如果它是一个插件? – Bergi

回答

1

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

修复:你的定义应该看起来像

interface ColorThief{ 
    new():any; 
}