logo
  • Home
  • Changelog
  • Documentation
logo
NuGet  .NET Core CLI  Code  
Donate with PayPal  

About

TypeGen is a single-class-per-file C# to TypeScript generator. Out of the box are available 2 utilities:

  • Command Line Interface that allows you to generate TypeScript files for your ASP.NET MVC/Core project(s)
  • Programmatical API for using file generation logic inside your own custom code
Below is a quick example of what TypeGen can do for you:
// use attribute on the type you want to generate

[ExportTsClass]
public class ProductDto
{
    public decimal Price { get; set; }
    public string[] Tags { get; set; }
}

// ...or use a generation spec

public class MyGenerationSpec : GenerationSpec
{
    public MyGenerationSpec()
    {
        AddClass<ProductDto>();
    }
}
translates to
// inside "product-dto.ts"

export class ProductDto {
    price: number;
    tags: string[];
}

Features

TypeScript generation

TypeGen allows you to generate TypeScript classes / interfaces / enums from C# classes and enums.

Single class per file

Every C# type is generated to a separate TypeScript file, to a location of your choice.

Collection/dictionary types

By default, all IEnumerable and IDictionary types are represented as TypeScript arrays and dictionaries.

Generic types

You can translate your generic type definitions to TS. Generic types can also be used for properties and fields.

Inheritance

Inheritance chains of any length can be represented in the generated TypeScript sources.

Primitive types

C# primitive types (int, string etc.) are by default translated to their corresponding TypeScript counterparts.

Excluding properties/fields

You can exclude (ignore) certain properties or fields from being generated to TypeScript.

Custom code style

Code style-related aspects, such as: tab size, string literal sign etc. can be customized.

Custom TypeScript code

You can include custom TypeScript code inside the generated sources and prevent it from being overridden.

Naming conventions

You can define your own custom logic for converting C# type/member names to TypeScript.

Adding files to project

TypeGen CLI can be configured to automatically add generated TS sources to your ASP.NET MVC project file.

Free

Last but not least, TypeGen is - and will always be - free!

© 2023 Jacek Burzyński
  • Report an issue
  • License