Dekiru.TypeScriptClientBuilder 6.2.0-preview.1

Prefix Reserved
This is a prerelease version of Dekiru.TypeScriptClientBuilder.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Dekiru.TypeScriptClientBuilder --version 6.2.0-preview.1
                    
NuGet\Install-Package Dekiru.TypeScriptClientBuilder -Version 6.2.0-preview.1
                    
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="Dekiru.TypeScriptClientBuilder" Version="6.2.0-preview.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dekiru.TypeScriptClientBuilder" Version="6.2.0-preview.1" />
                    
Directory.Packages.props
<PackageReference Include="Dekiru.TypeScriptClientBuilder" />
                    
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 Dekiru.TypeScriptClientBuilder --version 6.2.0-preview.1
                    
#r "nuget: Dekiru.TypeScriptClientBuilder, 6.2.0-preview.1"
                    
#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 Dekiru.TypeScriptClientBuilder@6.2.0-preview.1
                    
#: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=Dekiru.TypeScriptClientBuilder&version=6.2.0-preview.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Dekiru.TypeScriptClientBuilder&version=6.2.0-preview.1&prerelease
                    
Install as a Cake Tool

TypeScript Client Builder

A .NET library that automatically generates TypeScript client code and DTOs from ASP.NET Core controllers. Reduce boilerplate and keep your frontend and backend in sync.

Features

  • Automatic Client Generation: Generates TypeScript HTTP client methods from your ASP.NET Core controllers
  • DTO Export: Automatically exports C# DTOs to TypeScript interfaces
  • Enum Support: Multiple enum export options (numbers, strings, unions, const enums)
  • Type Safety: Full type safety between your C# API and TypeScript client
  • Inheritance Support: Optional support for inheritance chains in generated types
  • Customizable: Extensive configuration options for indentation, naming, and behavior
  • Checksum Optimization: Skip regeneration when nothing has changed
  • XML Documentation: Import your XML documentation comments into TypeScript
  • Flexible Parameters: Support for named parameters, headers, event callbacks, and more

Installation

Install via NuGet:

dotnet add package Dekiru.TypeScriptClientBuilder

Or via Package Manager Console:

Install-Package Dekiru.TypeScriptClientBuilder

Quick Start

Basic Usage

Add the following to your ASP.NET Core application (typically in Program.cs):

using TypeScriptClientBuilder;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();

var app = builder.Build();
app.MapControllers();

// Generate TypeScript client
ClientBuilder.Build(new ClientConfiguration
{
    Output = "ClientOutput"
});

app.Run();

This will scan all your controllers and generate TypeScript files in the ClientOutput directory.

Example Controller

[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
    [HttpGet(Name = "GetWeatherForecast")]
    public IEnumerable<WeatherForecast> Get(CancellationToken cancellationToken)
    {
        // Your implementation
    }
}

This generates a TypeScript client with type-safe methods to call your API.

Configuration Options

ClientConfiguration

Property Type Default Description
Output string Required Output directory for generated files
CleanOutput bool false Delete existing .ts files before generation
UseChecksum bool false Skip generation if checksum matches
UseVerboseLogging bool false Enable detailed logging
XmlDocumentationFile string null Path to XML documentation file
UseInheritance bool false Generate separate types for inheritance chains
EnumType EnumTypes None How to export enums (Strings, Union, Const)
ConvertNullablePropsToOptional bool false Convert nullable properties to optional
UseNamedParameters bool false Use object parameters instead of parameter lists
GenericMethods bool false Generate methods with generic return types
DisableTypeChecking bool true Add // @ts-nocheck to generated files
TypeFormatter Func<ExportedType, string> Identity Custom type name formatter
AddHeaderParameter bool false Include header parameter in methods
AddEventCallback bool false Include XHR event callback parameter
AddReturnXhrFlag bool false Include flag to return XHR object on error
LoggingCallback Action<string> null Custom logging callback
Indentation Indentation 4 spaces Indentation settings
IFormFileType string "Blob" TypeScript type for IFormFile
DefaultFileResultBehavior FileResultBehavior Redirect Behavior for file result methods
Includes HashSet<string> Empty Force include types (supports wildcards)

Example Configuration

ClientBuilder.Build(new ClientConfiguration
{
    Output = "wwwroot/api",
    CleanOutput = true,
    UseChecksum = true,
    XmlDocumentationFile = "bin/Debug/net8.0/MyApi.xml",
    EnumType = EnumTypes.Strings | EnumTypes.Union,
    ConvertNullablePropsToOptional = true,
    UseNamedParameters = true,
    Indentation = new Indentation 
    { 
        Character = ' ', 
        Size = 2 
    },
    LoggingCallback = message => Console.WriteLine($"[ClientBuilder] {message}")
});

Attributes

Controller & Method Attributes

[ClientBuilderAttribute]

Configure client generation at controller or method level:

[ClientBuilder(ClientBuilderSettings.AddHeader | ClientBuilderSettings.AddEventCallback)]
public class MyController : ControllerBase
{
    [ClientBuilder(ClientBuilderSettings.OmitHeader)]
    public IActionResult MyMethod() { }
}
[ClientBuilderIgnore]

Exclude controllers, methods, properties, or parameters from generation:

[ClientBuilderIgnore]
public class InternalController : ControllerBase { }
[ClientBuilderMethodName]

Override the generated method name:

[ClientBuilderMethodName("fetchWeather")]
public IActionResult GetWeather() { }
[ClientBuilderReturnsUrl] / [ClientBuilderRedirect]

Control file download behavior (GET requests only):

[ClientBuilderReturnsUrl]
public FileResult DownloadFile() { }
[AddQueryParameter]

Add query parameters without declaring them in the method:

[AddQueryParameter("version", typeof(int))]
public IActionResult Get() { }

Type Attributes

[UnionType]

Generate string union types:

public class Model
{
    [UnionType("success", "error", "pending")]
    public string Status { get; set; }
}

Generates: status: "success" | "error" | "pending"

[KeyOf]

Generate keyof types:

public class Model
{
    [KeyOf(typeof(User))]
    public string Field { get; set; }
}

Generates: field: keyof User

[TypedIdOf]

Override property type:

public class Model
{
    [TypedIdOf(typeof(User))]
    public int UserId { get; set; }
}
[Partial]

Generate Partial<T> types:

public IActionResult Update([Partial] User user) { }
[Nullable] / [Optional]

Mark properties as nullable or optional:

public class Model
{
    [Nullable]
    public string Name { get; set; }
    
    [Optional]
    public int? Age { get; set; }
}

Supported Frameworks

  • .NET 8.0
  • .NET 9.0
  • .NET 10.0

Development

Building

dotnet build

Running Sample

The Sample project demonstrates the library's features:

cd Sample
dotnet run

Check the Output directory for generated TypeScript files.

Publishing to NuGet (Internal use only)

  1. Update version in Source/TypeScriptClientBuilder.csproj:

    <BaseVersion>6.2.0</BaseVersion>
    <PreviewVersion>-preview.1</PreviewVersion>
    

    Preview versions will have -preview.x suffix, while stable releases will leave the PreviewVersion empty.

  2. Commit and push changes

  3. Run the DevOps pipeline

  4. Package will appear on nuget.org within a few minutes

License

MIT

Authors

Dekiru Solutions

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

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
6.2.0 88 3/11/2026
6.2.0-preview.1 48 2/13/2026
6.2.0-preview.0 51 2/13/2026
6.1.3 359 10/20/2025
6.1.2 195 10/15/2025
6.1.1 191 10/15/2025
6.1.0 273 9/19/2025
6.1.0-preview.1 173 8/13/2025
6.1.0-preview.0 147 6/3/2025
6.0.4 648 3/4/2025
6.0.3 201 3/3/2025
6.0.2 191 2/20/2025
6.0.1 176 1/30/2025
6.0.0-preview 159 10/11/2024
5.0.16 3,996 8/29/2024
5.0.15 809 5/30/2024
5.0.13 173 5/30/2024
5.0.12 179 5/24/2024
5.0.11 398 4/9/2024
5.0.10 359 3/15/2024
Loading failed