typescript - How to use 'new' for jQuery.Event() -
using existing definitelytyped jquery.d.ts declarations, not able this:
/// <reference path="../scripts/typings/jquery/jquery.d.ts" /> declare var firstevent; var newevent = new jquery.event(firstevent);
but generates compiler error:
testing.ts(3,19): new expression valid on constructors
and according jquery.d.ts, makes sense because jquery.event defined function not type.
i can force cast any:
/// <reference path="../scripts/typings/jquery/jquery.d.ts" /> declare var firstevent; var newevent = new <any>jquery.event(firstevent);
but sledgehammer feels wrong.
is limitation of typescript declarations or limitation in definition of jquery.d.ts?
this shortcoming in jquery definition file. can represent callable-or-newable thing (written here using explicit interfaces clarity; use type literal well):
interface callableornewable { (arg: string); new (arg: string); } interface thing { event: callableornewable; } var x: thing; new x.event(''); // ok x.event(''); // ok
Comments
Post a Comment