TypeLite generation of enums or get rid of word const

Hello everybody,

today I want to display one trick for working with TypeLite.

But before this trick few words about TypeLite. 

So, imagine that you created some C# class library according to business logic requirements with some models in C#. As usually on client side very similar task will be done by hands of javascript developer or front end developer which uses typescript. In order to leave back end developers and front end developers in sync, you can use some library, which take C# model and generates needed typescript class. Wouldn't it be great? And there are tools which can take C# class and generate TypeScript class. The name of this tool is TypeLite.

It has two options of working:

1. Via usage of T4

2. Via attributes.

I will skip detailed description how to configure TypeLite. I just want to mention one part of code which made my day.


By default enums are generated into TypeScript as const values:

export const enum Honorific {
Mr = 0,
Ms = 1

but with mentioned line of code it will be generated like this:

export enum Honorific {
Mr = 0,
Ms = 1


Comments (1) -

  • Thanks you so much for this post!

Add comment