Feature Request: Runtime Type Info and Annotations

Topics: General, Language Specification
Apr 16, 2014 at 8:17 PM
Hello TypeScript team. Congrats on reaching 1.0! Now, on to the next thing ;)

I'm currently working with Google as part of the AngularJS 2.0 Core Team. Our new implementation work is being done entirely in ES6 using the Traceur compiler. As you probably know, Traceur allows compiling of ES6 code into ES5 code. However, you may not know that it does support a few additional features such as types and annotations. The compiler itself does not use the type or annotation info, but instead writes it into a metadata structure attached to the annotated functions. By doing this we are able to use the type info at runtime. This is enabled by a special switch on the Traceur compiler.

Since TypeScript already has the type information, I'd love to see something like this added. Having an optional switch for the TypeScript compiler to have it encode this metadata would be very valuable. Currently the AngularJS 2.0 team is using this information for both unit testing and for our new dependency injection framework. It would be a tremendous win for Microsoft and TypeScript developers if they could take advantage of Angular's new runtime type assertion capabilities and its dependency injection without having to do anything special in their code. To this end, we have some pretty simple structures being emitted from the Tracuer compiler and I would be happy to meet with you and explain them (though they don't need much explaining.)

We are also using annotations (attributes for c# devs) which are written to the same structures. This is a bit more involved for TypeScript because it would require language support. I know this has already been asked for by developers with no relation to our project, so it's likely others have a need for it. Traceur already handles this and it would be amazing if both Traceur and TypeScript emitted annotation and type info in the same format.

You can see a little bit about these features in Traceur here. I'm happy to talk about this in more detail. Looking forward to hearing from you.
Apr 17, 2014 at 8:00 AM
This sounds very interesting indeed.
Apr 17, 2014 at 8:03 AM
Annotations seem to be pretty nice and simple:


(you need to go to Options > Show all options > annotations near the end to get it working).

The runtime type info is a frequently requested feature. See this discussion: https://typescript.codeplex.com/discussions/397586
Jul 2, 2014 at 1:51 AM
This would be very useful indeed.