Marc
Marc

Reputation: 4813

TypeScript pre-/marco-compiler for Visual Studio and C#

We use TypeScript a lot in ASP.Net MVC projects for implementing the client-side code (MVVM, Ajax, etc). We always face the problem that TypeScript/Javascript code is out of sync with C# server-code as R# and other Tools don't get over the "technology gap" from C# to TypeScript.

For example when the server returns JSON objects and one of the fields get renamed one need to search the whole TS sourcecode and renamed it there by hand otherwise the client doesn't work as expected anymore. This also adresses MVVM pattern where the HTML markup (and therefore the binding) is generated by Razor/C# and the client-viewmodel by TypeScript. Same problem.

One solution to this that cam in mind is a TypeScript Pre-Processor or Macro's. It would be very cool if I can mix C# code (eg. constants like field-/property-names into the TypeScript code. This stuff gets updated each time before the TS compiler starts and does generate the TS sourcecode before it get to the TS compiler.

Is may be a way to bridge the technology-gap and may allow to fix a lot of problems because the same constants (eg. names) can be used in server-side C# code as well as in client-side TS code. Same would apply to plain Javascript code instead of TypeScript.

Does anything like this already exists? How did you handle that gap between client and server code? How to keep things in sync? Any feedback to such an approach?

Cheers, Marc

Upvotes: 0

Views: 286

Answers (2)

basarat
basarat

Reputation: 276255

Typelite http://type.litesolutions.net/ will generate Typescript interfaces (for json DTOs) for you as your C# code changes

Upvotes: 1

Wtf1sh
Wtf1sh

Reputation: 137

Since TypeScript code is typed, it should be easy to refactor when needed. Why are you renaming it by hand? :/ Altough that still involves some manual work, I believe refactoring is the best you can get now. I don't know of any tools that would do the job that you require fully automatically. Stronger link between C# and TypeScript code might be a possibility in the future.

Upvotes: 0

Related Questions