10 March, 2013

TypeLITE - TypeScript interfaces from .NET classes

In the last few weeks I was doing some client-side development in TypeScript. It is amazing tool, that increased my productivity in client-side development dramatically.

To streamline the integration between TypeScript and C# code on the server I wrote a simple utility that generates TypeScript interfaces from our POCO classes. It help us a lot in keeping our client-side code in sync with the server side-code - when a server-side class changes, TypeScript interface is automatically updated and if the TypeScript code isn't compatible with the updated interface, TypeScript compilation fails with nice, descriptive message - a huge difference form previous experience with pure JavaScript.

I think this utility might be useful for other developers, so I made it available under MIT license. It's called TypeLITE.

Example

POCO classes
public class Person {
    public string Name { get; set; }
    public int YearOfBirth { get; set; }

    public Address PrimaryAddress { get; set; }
    public List<address> Addresses { get; set; }
}

public class Employee : Person {
    public decimal Salary { get; set; }
}

public class Address {
    public string Street { get; set; }
    public string Town { get; set; }
}

Generated TypeScript interfaces
interface Person {
  Name: string;
  YearOfBirth: number;
  PrimaryAddress: Address;
  Addresses: Address[];
}

interface Employee extends Person {
  Salary: number;
}

interface Address {
  Street: string;
  Town: string;
}

Usage instructions are available on Bitbucket on the project page. Any comments or suggestions are welcome.

1 comment:

  1. Fantastic project! You really did an outstanding job with this. Great documentation, very easy to use, very extensible and customizable. I love the formatters, the syntax, everything! We will be using this quite a bit and I'll be sending more feedback as we use it more. Thanks for all the outstanding work!

    ReplyDelete