Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can typescript compiler produce POCO .NET types/assembly?

Tags:

c#

typescript

I'm getting into app development using knockout with MVC and EF and I'm looking at how adding TypeScript to the recipe might help me out.

I like the cleaner mechanism for authoring in the IDE but the missing thing seems to be the ability to reference the interfaces defined in typescript from other .NET assemblies.

Am I right that there's nothing stopping this from happening other than it hasn't been done? I'm curious if there a demand for it or if I am looking at the problem domain in a way that others aren't.

The reason I see utility is because currently I have no way to define a given DTO in just one place. I have to either author them separately in my C# View model and javascript/typescript or I have to use something like the knockout mapping plugin which is too much "magic" for my tastes.

Note: I'm not asking for arbitrary typescript to .NET conversion. I'd just like typescript interfaces to produce usable .NET POCO types.

Note2: I just found http://typescript.codeplex.com/ which does what I'm asking in the opposite direction (from .NET to typescript) and this actually might be sufficient for the problem I'm expressing in this question.

like image 501
Aaron Anodide Avatar asked Oct 04 '22 09:10

Aaron Anodide


1 Answers

There is a utility to convert C# classes into Typescript : http://type.litesolutions.net/

This way you can have your DTOs in one place i.e. C#. Available on Nuget and is open source on BitBucket so feel free to modify (even the code generation) and contribute.

like image 191
basarat Avatar answered Oct 13 '22 12:10

basarat