5

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.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Aaron Anodide
  • 16,906
  • 15
  • 62
  • 121
  • I'm not entirely sure if this is what you're looking for, but there's a bunch of definition files on https://github.com/borisyankov/DefinitelyTyped – jbabey Apr 17 '13 at 20:08
  • I am writing a Visual Studio extension called TypeSharp that does C# to TypeScript conversion. If you are interested in trying a pre release version email me at davemckeown@outlook.com - It will be an open source tool – dmck Apr 17 '13 at 22:38
  • thanks, I sent you an email.. – Aaron Anodide Apr 17 '13 at 23:11
  • The repo for the TypeSharp project is now public at http://github.com/davemckeown/TypeSharp – dmck Aug 09 '13 at 20:55

5 Answers5

3

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.

basarat
  • 261,912
  • 58
  • 460
  • 511
1

Check out my answer at: Breeze.js typed entities

You can't use my solution in knockout templates, but it definitely helps on the TypeScript side.

Community
  • 1
  • 1
Alex Dresko
  • 5,179
  • 3
  • 37
  • 57
0

I approached this problem by serializing to JSON and back. Depending on your needs, the ease of this is worth is, and if your doc is complicated, its necessary.

Brian Rasmussen
  • 114,645
  • 34
  • 221
  • 317
Nathan Bellowe
  • 4,662
  • 3
  • 15
  • 16
0

As of version 1.7, Bridge supports the generation of TypeScript definitions for C# types. In this article, you learn how to instruct the Bridge compiler to emit .d.ts alongside the matching .js files and use them in a Visual Studio TypeScript project

http://bridge.net/docs/generate-typescript-definitions/

George Birbilis
  • 2,782
  • 2
  • 33
  • 35
0

Typewriter is a free extension for Visual Studio that generates TypeScript files from c# code files using TypeScript Templates.This allows you to create fully typed TypeScript representations of server side API, models, controllers, SignalR hubs etc. that automatically updates when you make changes to your c# code.By doing this you get TypeScript Intellisense and compile-time errors when the client- and server side code differs. This speeds up your development pace and increases the quality of your applications.

https://frhagn.github.io/Typewriter/

George Birbilis
  • 2,782
  • 2
  • 33
  • 35