Question

Trying to decide between the two for an asp.net mvc single-page application. One thing I can't seem to find out about TypeScript is if can I reference a TypeScript class server side, for example in a controller or model. I tried it but it doesn't seem to work.

I've tried SharpScript (Script#?) and I love that I can code a class in C#, and now from one single file, I have access to that class ServerSide and ClientSide since Script# converts the C# class into a javascript file automatically. This makes it easy to have one single class that I can use to populate a model, then use it with HtmlHelpers to setup a view, web api uses it to return json, and then clientside, reference the model via javascript for all my clientside stuff. I don't have to code two different files for each end.

Does Typescript offer this also? Or is Typescript only for client side use?

I'm wondering if I need both? I use Script# for those classes I want access to from both ends and I use TypeScript for the clientside browser only logic.

EDIT 1 - Turns out I was actually using something called SharpKit in another project. That is what was generating my javascript files from C# and allowing me to use one single C# class at both ends. As soon as I add Script# via nuget to my test asp.net mvc project, it stops compiling.

FINAL DECISION - Not going to use Script#. No support. No docs. Can't even compile my app with it. Not worth troubleshooting if it's just another variation of what TypeScript is. Also not going to bother trying to use TypeScript server side either via TypeLITE since there's really no support or anybody using that TypeLITE either. Plus, I want to be able to have a single C# class with a string property that gets auto mapped to a javascript knockout observable and it seems like SharpKit is the only thing that can handle this.

Looks like SharpKit is really what I want to stick with since it does everything I want, keeps me in C# (even better!), and has a lot of support. Just need to hope I don't hit the 5000line limit and then need to buy it. Maybe I will give TypeScript a shot, but it seems like once I am using SharpKit, I don't really gain anything with TypeScript.

Was it helpful?

Solution

There are projects that will generate the equivalent TypeScript classes from your C# code if this is what you are after - but TypeScript isn't callable from C# (well it could be if you really wanted, but not by design).

Whether TypeScript or Script# is most appropriate for your specific case is hard to say, you'll have to make a judgement call on that one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top