This project is read-only.

Enforce array of type references

Topics: Language Specification
Oct 8, 2013 at 5:05 AM
Edited Oct 8, 2013 at 5:07 AM
Is there a way to enforce an array of type references? For example:
function doSomething(types: Function[]) { }
That is the best I came up with so far; however, I have to cast all my types to functions (which they are already), and I don't want the "any" type.
Oct 8, 2013 at 9:23 PM
What do you mean by type references exactly? Are you trying to do something nominal? I'm not sure why you're needing to cast, an array of objects with call signatures should be a perfectly acceptable argument to doSomething without casts.
Oct 8, 2013 at 9:41 PM
I mean this:
class A { }
class B { }
class C { }
function doSomething(types: Function[]) { }
doSomething([A, B, C]);
Doesn't work without casting A, B, and C to "Function".
Oct 8, 2013 at 10:38 PM
I thought that should work so I tested it out on the TypeScript Playground and it works there.
Oct 8, 2013 at 11:05 PM
Edited Oct 8, 2013 at 11:07 PM
Not sure what happened now. I had code similar to the above that wasn't working, but the code above is working. Perhaps the compiler is playing tricks on me (again). :(