Add some new features

Topics: Language Specification
Apr 25, 2014 at 7:00 AM
1) Reflector by object instance (just like that in C#, maybe we can dynamically call functions, methods……)

2) Reflector by string to dynamically create object instance.

3) Add "protected" key word
Apr 25, 2014 at 10:44 AM
There are already feature requests for type info and inheritance modifiers - just to a search in the "issues" tab.
Apr 26, 2014 at 12:43 PM
Do you mean all?
Apr 26, 2014 at 6:02 PM
Apr 27, 2014 at 8:32 AM
OK, I mean we can use something like Assembly.Load(A string value of TypeScript) to get an instance of TS's instance.
Apr 27, 2014 at 3:55 PM
Not sure that wording makes sense - you want to make an instance of TypeScript? As in, the compiler?

I think what you are trying to say is you want TS to output a JS code layer that has all the type info so, during a full minification scenario, you can pass in "Some.Namespace.Type" to create types? First, unless TS supports minification natively, that may not even be possible; and, if the code isn't minimized, then you could easily type "new Some.Namespace.Type()" (which normally you can do even minimized). You can also dynamically call functions and create types as well in JS, so reflection is not needed for that.

If you mean to load entire files like assemblies, TS already supports modules.
Apr 28, 2014 at 5:12 AM
Many thanks!
Then what about converting a string value to an enum in TypeScript? I mean:
public enum Test
{
   A,
   B
}
Then you can say this in TS:
var t:Test = Enum.Parse("A"); //Something or someway in C# to convert a string to enum.
Apr 28, 2014 at 7:55 AM
You should try typing code in here: http://www.typescriptlang.org/Playground/

Then you can see what is going on. Your code above (without the "public" modifier) produces this:
var Test;
(function (Test) {
    Test[Test["A"] = 0] = "A";
    Test[Test["B"] = 1] = "B";
})(Test || (Test = {}));
So, Test[Test.A] == "A" and Test[Test.B] == "B".
Apr 28, 2014 at 9:22 AM
Many thanks jamesnw:

So there comes an interesting question:Oh yes, I agree that your way to my specific enum (e.g: Test) is right. But I wanna make that "more generic"——
I mean that I can have a method to reflect and get values to unsure enum (The "unsure enum" means any kind of enum, not just the example given above).
Do you think about reflection is needed? Maybe go back to the previous question.
Haha……
Apr 28, 2014 at 12:33 PM
Edited Apr 28, 2014 at 2:04 PM
You can add in your own type details yourself (i.e. Test["_type"] = "Test", or perform duck-typing. If you are talking about wanting TS type details that are not in JS then we are back to the links I posted. ;). What you are looking for is RTTI (runtime type information) for JS, and that would explode the file size, or require a separate file be made (perhaps JSON format).