.d.ts members resolving/emitting to literals

Topics: Language Specification
Jan 3, 2013 at 4:58 PM
Edited Jan 3, 2013 at 6:35 PM

I know that enums are under consideration and may not be implemented, but I wanted to use them as an example of what I think would be a useful feature.  Essentially, I believe the usefulness of the interface definitions would be enhanced if they could generate literals.


// typescript
enum MyEnum
        foo = "foo", bar = "bar"

could generate javascript:


This is the most basic example I could think of, but I think there is room to expand on the concept to include more than just literals but more complex expressions that are still evaluated at compile-time.


declare module xample{
interface iFace {
        static SomeFunc(parm1: string, parm2: int32): string = (p1, p2) {
			return p1.subString(p2);

var value = iFace.SomeFunc("FooBar", 3);

generates javascript

var value = "Bar";