Reputation: 3169
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:
Upvotes: 7
Views: 3521
Reputation: 21
This worked for me:
class MyView1 extends (Polymer.Element as {new(): any}) {
...
}
Upvotes: 0
Reputation: 10015
Usually, this is because you there is conditional logic which alters what the superclass can be. For instance --
class A {
constructor() {
super(/* anything */);
}
}
class B {
constructor() {
super(/* anything */);
}
}
var X = { prod: A, qa: A, dev: B, mock: B }[ environment.type ]; // inline map
class C extends X {
constructor() {
super(/* anything */);
}
}
-- can yield this behavior if type
is not even declared on environment
, or [potentially] if TypeScript especially thinks that X
could be something other that a class which takes the arguments being provided by the subclass.
Upvotes: 0
Reputation: 40554
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.
Upvotes: 2