Type for objects wrappable by jquery

Topics: General
Sep 25, 2013 at 10:36 AM
Edited Nov 14, 2013 at 1:07 PM
I need to type existing functions that can accept multiple arguments of any type that is wrappable by jquery, ie:
declare function foo(x: JQueryable, y: JQueryable);
While above works if I define empty JQueryable interface, obviously it is not very type safe.
Since sum types were rejected (Issue 120), is there some other type safe solution to this problem ? Overloading is not acceptable due to number of possible combinations.
Nov 14, 2013 at 1:06 PM
Edited Nov 14, 2013 at 1:07 PM
It's possible to emulate sum type of interfaces:
interface JQueryable {

interface String extends JQueryable { }
interface HTMLElement extends JQueryable { }
interface JQuery extends JQueryable { }
Unfortunately this breaks for String type when it's defined in separate file. See issue 1892.
Nov 14, 2013 at 4:01 PM
Since sum types were rejected...
It was closed, but it's back due to popular demand: