I'm trying to use the Foundation's Reveal plugin in my Typescript code in following way (altered for readability):
var popup = new Foundation.Reveal($('#element'));
and I'm getting following error during compilation (in the end it does compile and work anyway):
TS2350: Only a void function can be called with the 'new' keyword.
How should I write it then?
Typescript Playground - code illustrating the problem
I find a way to shut the typescript compiler up, but this will give up the type check(Do it with your caution).
var popup = new (Foundation.Reveal as any)($('#element'));
More example:
function User2(name) {
if (this instanceof User2) {
this.name = name;
}
else {
return new (User2 as any)(name);
}
}
Based on the interface:
interface FoundationSitesStatic {
Reveal(element:Object, options?:IRevealOptions): Reveal;
}
you cannot call it with the new
operator (used to call a constructor).
So fix:
var popup = Foundation.Reveal($('#element'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With