ColesTypescriptToCSharp 1.0.0
The owner has unlisted this package.
This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package ColesTypescriptToCSharp --version 1.0.0
NuGet\Install-Package ColesTypescriptToCSharp -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="ColesTypescriptToCSharp" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ColesTypescriptToCSharp" Version="1.0.0" />
<PackageReference Include="ColesTypescriptToCSharp" />
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 ColesTypescriptToCSharp --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ColesTypescriptToCSharp, 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 ColesTypescriptToCSharp@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=ColesTypescriptToCSharp&version=1.0.0
#tool nuget:?package=ColesTypescriptToCSharp&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
CSharpToTypeScript
A .NET library that converts C# types to TypeScript type definitions. It recursively discovers related types and generates properly organized .ts files with imports.
Features
- Automatic Type Discovery - Add root types and all related types are automatically discovered
- Namespace Organization - Types are grouped into separate
.tsfiles by namespace - Cross-Namespace Imports - Automatically generates import statements between files
- Inheritance Support - Emits
extendsclauses for class hierarchies - Comprehensive Type Mapping - Handles primitives, collections, generics, enums, records, and more
- JSON Attribute Support - Respects
[JsonIgnore]and[JsonPropertyName]attributes - Configurable Output - Customize naming conventions, enum styles, and nullability handling
Installation
dotnet add package CSharpToTypeScript
Quick Start
using SessionTracker;
// Create a converter with default options
var converter = new TypeScriptConverter();
// Add root types - related types are discovered automatically
converter.AddType<Order>();
// Generate files to a directory
converter.WriteToDirectory("./generated-types");
Configuration
var converter = new TypeScriptConverter(new TypeScriptConverterOptions
{
// Enum output style: Numeric or StringLiteral
EnumStyle = EnumStyle.StringLiteral,
// Property naming: CamelCase or PreserveOriginal
PropertyNaming = PropertyNamingStyle.CamelCase,
// File naming: Dots (MyApp.Models.ts) or Underscores (MyApp_Models.ts)
FileNaming = FileNamingStyle.Dots,
// Include 'extends' for classes with base types
IncludeInheritance = true,
// Honor [JsonIgnore], [JsonPropertyName] attributes
RespectJsonAttributes = true,
// Nullable handling: UseNullUnion (T | null), Optional (T?), or Ignore
NullableHandling = NullableHandling.UseNullUnion,
// Generate index.ts barrel file
GenerateBarrelFile = true,
});
Example
Given these C# types:
namespace MyApp.Models
{
public class User
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime CreatedAt { get; set; }
}
}
namespace MyApp.Models.Orders
{
public class Order
{
public Guid Id { get; set; }
public User Customer { get; set; }
public List<OrderItem> Items { get; set; }
public OrderStatus Status { get; set; }
}
public enum OrderStatus { Pending, Shipped, Delivered }
}
The converter generates:
MyApp.Models.ts
export interface User {
id: number;
name: string;
createdAt: string;
}
MyApp.Models.Orders.ts
import { User } from './MyApp.Models';
export interface Order {
id: string;
customer: User;
items: OrderItem[];
status: OrderStatus;
}
export interface OrderItem {
productName: string;
price: number;
quantity: number;
}
export enum OrderStatus {
Pending = 0,
Shipped = 1,
Delivered = 2,
}
Type Mapping Reference
| C# Type | TypeScript Type |
|---|---|
string, char, Guid, DateTime |
string |
int, long, float, double, decimal |
number |
bool |
boolean |
T[], List<T>, IEnumerable<T> |
T[] |
Dictionary<K,V> |
Record<K, V> |
T? (nullable) |
T \| null |
Task<T> |
T (unwrapped) |
(T1, T2) (tuple) |
[T1, T2] |
enum |
enum or string union |
[Flags] enum |
number |
class, record, struct |
interface |
In-Memory Generation
// Get output without writing to disk
Dictionary<string, string> files = converter.GetOutput();
foreach (var (fileName, content) in files)
{
Console.WriteLine($"=== {fileName} ===");
Console.WriteLine(content);
}
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
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 |
|---|
Initial release with support for classes, records, enums, generics, inheritance, and JSON attribute handling.