Search code examples
javascriptjquerytypescriptflot

TypeScript's tsc compiler emits errors when calling jQuery and Flot code


With this code (a branch of a GitHub repository) running "make" on x86-64 Linux gives me these errors:

shlomif@telaviv1:~/Download/unpack/to-del/TypeScript-flot$ make tsc --outFile foo.js foo.ts foo.ts(18,12): error TS2345: Argument of type 'string' is not assignable to parameter of type 'JQuery'. foo.ts(47,39): error TS2345: Argument of type '(event: JQueryEventObject, pos: any, item: any) => void' is not assignable to parameter of type 'boolean'. foo.ts(68,39): error TS2345: Argument of type '(event: JQueryEventObject, pos: any, item: any) => void' is not assignable to parameter of type 'boolean'. foo.ts(71,5): error TS2304: Cannot find name 'plot'. foo.ts(74,40): error TS2339: Property 'version' does not exist on type '{ (placeholder: JQuery, data: dataSeries[], options?: plotOptions): plot; (placeholder: JQuery, d...'. Makefile:6: recipe for target 'foo.js' failed make: *** [foo.js] Error 2

The TypeScript code in question is:

```

$.plot("#placeholder", [ // line 18
        { data: series[0], label: "old-time(iters)", },
        { data: series[1], label: "new-time(iters)", },
    ],
    {
        series: {
            lines: {
                show: true
            },
            points: {
                show: true
            }
        },
        grid: {
            hoverable: true,
            clickable: true
        },
    }
);

```

I'm using TypeScript's tsc compiler along with the jquery definitions from https://github.com/DefinitelyTyped/DefinitelyTyped and a locally modified version of the jQuery Flot definitions (which fixes some other errors reported by the tsc compiler).

How can I fix these errors?


Solution

  • The error states it can't assign a string type to a jQuery type on the 18th line:

    $.plot("#placeholder", [
    

    Changing line 18 to a jQuery object should fix it:

    $.plot($("#placeholder"), [