Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Call target does not contain any signature" for call to super() without typings file

Tags:

typescript

I'm trying to make Polymer 2.0 work with Typescript and am running into issues when making a constructor where libraries - including Polymer 2 - do not expose a proper typings file. In the simplest case:

class MyView1 extends Polymer.Element {
    public static is = 'my-view1';

    constructor() {
        super(); // [ts] Call target does not contain any signature
    }
}

To make it compile at all without the constructor, I've done a declare var Polymer: any; in a main .d.ts file.

Now, I have two questions:

  1. How (if at all) can I make typescript ignore this and just assume there's a super constructor it can call?
  2. How (if at all) do I declare a typings file that contains a signature for the super class? I haven't been able to find the right documentation for this (and the various use cases I've run into so far) yet.
like image 414
cthulhu Avatar asked Jul 06 '17 11:07

cthulhu


1 Answers

You can just expand your declaration to include a constructor in the Element property:

declare var Polymer: {
    Element: {
        new ();
    }
};

For your second question, you can just move this to a *.d.ts file. See the documentation on creating declaration files.

like image 187
Saravana Avatar answered Nov 05 '22 03:11

Saravana