TSBindGen 1.0.0

dotnet add package TSBindGen --version 1.0.0
                    
NuGet\Install-Package TSBindGen -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TSBindGen" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TSBindGen" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="TSBindGen" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TSBindGen --version 1.0.0
                    
#r "nuget: TSBindGen, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TSBindGen@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TSBindGen&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=TSBindGen&version=1.0.0
                    
Install as a Cake Tool

TSBindGen

Reflection-based generation of typescript definitions from C# types.

Description

This is a typescript types generator in order to ease the usage of your already defined C# types on a TypeScript client. It is reflection based in order to be both configurable from within the code, and to be able to resolve dependent types. When you provide a list of types, the function will generate the requested types, along with any other types that are needed for it's representation, converging on a complete type definition graph that spawns from the requested list.

The library is composed of a single static class, at any point of an application, call into TSGenerator.GenerateTypes to generate the resulting type declarations. The function allows for passing either a list of types or an Assembly plus a list of namespaces, that way you can select what types to generate and which ones to ignore however it is more convenient for each codebase. It is possible to get a string in return or to provide a TextWriter as the last argument, which can be used to write directly to a file.

Example:

string path = "../frontend/src/types/generated.ts";
using (var sink = new StringWriter(path)){
    TSGenerator.GenerateTypes(Assembly.GetExecutingAssembly(), ["MyApp.Models.API", "MyApp.Models.DTOs"], sink);
}

It is also possible to get the result as string:

string tsTypes = TSGenerator.GenerateTypes(typeof(MyType1));

Since it is reflection-based, it should be compatible with any C# type that can be inspected at runtime. There are some edge cases for which any or unknown are used since the result could not be determined. The expectation is that on those cases you can still use it as a base for a full-fledged type, use it as a startint point for a client-side transformation, or just go with the less type-safe option of leaving it as-is.

Installation

The recommendation is to download and vendor the file src/TSBindGen/TSGenerator.cs into your own codebase. Since it is a small single file and simple enough to be modified, there is no need for downloading a whole nuget package, plus it is easier to adjust whatever is needed for your specific use-case that way (for example in order to fix an edge-case without needing to either alter your model or generalizing it so it can be merged).

If you still prefer or need a nuget package, there should be one available soon.

dotnet add TSBindGen

Why another TypeScript Generator

There are many tools for generation TypeScript definitions for your C# projects, but usually they either parse the source code and translate it, or depend on adding properties or other tags through your whole program. While they tend to work fine, I find it either lacking of context or unnecesarily complex.

The idea is that, since each project and team is different, the bindings between your frontend and backend should live in the code itself, so it can be configured and adapted as the project evolves. You can run it at application startup on development, run either generation or the app depending on a parameter, try to hook it at compile time. It is a just simple no-dependencies C# function that you can run on any context that suits your project.

License

TSBindGen is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows the usage in close-source and commercial projects. Attribution is appreciated but not required. Check LICENSE for more details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 206 1/18/2026