0

This is how my typescript file looks like.

/// <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);
    }
}

During compilation getting error message

Cannot find name 'ColorThief'.

Here is the color thief plugin that I want to use and it's already included in html markup

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

What am I doing wrong?

heron
  • 3,611
  • 25
  • 80
  • 148

1 Answers1

1

You defined it as a jquery plugin however its actually just a JavaScript class

Fix: Your definition should look like

interface ColorThief{
  new ():any;
}
basarat
  • 261,912
  • 58
  • 460
  • 511