CsTsTypeGen 0.0.6

dotnet add package CsTsTypeGen --version 0.0.6
                    
NuGet\Install-Package CsTsTypeGen -Version 0.0.6
                    
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="CsTsTypeGen" Version="0.0.6">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CsTsTypeGen" Version="0.0.6" />
                    
Directory.Packages.props
<PackageReference Include="CsTsTypeGen">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 CsTsTypeGen --version 0.0.6
                    
#r "nuget: CsTsTypeGen, 0.0.6"
                    
#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.
#addin nuget:?package=CsTsTypeGen&version=0.0.6
                    
Install CsTsTypeGen as a Cake Addin
#tool nuget:?package=CsTsTypeGen&version=0.0.6
                    
Install CsTsTypeGen as a Cake Tool

CsTsTypeGen

NuGet

A streamlined tool to generate a typedefs.d.ts TypeScript type definitions file from all of your C# types in the entire codebase.

Works with vanilla no build js and the built in ts lsp in vs code intellisense. With this tool you can have your types defined in your C# code, use DTO + json + http to send data directly to the frontend, annotate the types on the frontend with jsdoc, and get autocomplete for your js code.

Features

  • Automatic Generation: TypeScript definitions are generated automatically on project build
  • Seamless Integration: Works with MSBuild and requires minimal configuration
  • Comprehensive Type Mapping: Handles C# classes, interfaces, enums, and properties
  • Documentation Support: Preserves C# XML documentation as JSDoc comments
  • Nullable Support: Preserves nullability information from C#

Installation

# Install as a .NET tool and package reference in one command
dotnet add package CsTsTypeGen

Quick Start

After installing the package, TypeScript definitions will be generated automatically when you build your project. The default output file is typedefs.d.ts in your project directory.

To use the generated TypeScript definitions in your JavaScript/TypeScript files, add the reference at the top, with your correct path, and add a type annotation with your type:

/// <reference path="../../typedefs.d.ts" />
// @ts-check

/** @type {Ui.Components.MetricsData} */
let chartData = null;

Configuration

You can customize the behavior by adding the following properties to your .csproj file:

<PropertyGroup>
  
  <CsTsTypeGen_GenerateDefinitions>true</CsTsTypeGen_GenerateDefinitions>
  
  <CsTsTypeGen_DefinitionsPath>$(MSBuildProjectDirectory)/typedefs.d.ts</CsTsTypeGen_DefinitionsPath>
  
  <CsTsTypeGen_SourceDirectory>$(MSBuildProjectDirectory)/..</CsTsTypeGen_SourceDirectory>
</PropertyGroup>

These properties are automatically used by the MSBuild targets that are imported when you reference the package, and are passed to the tool as environment variables with the CsTsTypeGen_ prefix.

Manual Usage

You can also run the tool manually:

# Using command line arguments
dotnet tool run cstsgen -- <source-directory> <output-file>

# Or using environment variables
CsTsTypeGen_SourceDirectory=<source-directory> CsTsTypeGen_DefinitionsPath=<output-file> dotnet tool run cstsgen

Type Mapping

CsTsTypeGen maps C# types to TypeScript types as follows:

C# Type TypeScript Type
string string
int, long, decimal, float, double number
bool boolean
DateTime, DateTimeOffset string
Guid string
ICollection<T>, List<T>, IList<T> T[]
DbSet<T> DbSet<T>
enum Union type + enum
class, interface interface
Nullable<T> or T? Optional property

Develop

dotnet clean && dotnet build -c Release && dotnet pack -c Release

License

This project is dual-licensed:

  • Community Edition: GNU AGPLv3 (see LICENSE)
  • Commercial License: Available for proprietary SaaS and embedded use

If you would like to use this software in a proprietary, closed-source SaaS or on-prem product, contact kruserr for commercial licensing options.

By contributing, you agree to our Contributor License Agreement.

There are no supported framework assets in this 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
0.0.6 114 3/30/2025
0.0.5 100 3/30/2025
0.0.4 105 3/30/2025
0.0.3 98 3/30/2025
0.0.2 103 3/30/2025
0.0.1 99 3/30/2025