// docs / generics

Generics

TypeSharp maps C# generic collections and types to their TypeScript equivalents.

Collection mappings

C#TypeScript
List<T>T[]
IList<T>T[]
IEnumerable<T>T[]
ICollection<T>T[]
IReadOnlyList<T>readonly T[]
HashSet<T>T[]
ISet<T>T[]
Dictionary<K, V>Record<K, V>
IDictionary<K, V>Record<K, V>
IReadOnlyDictionary<K, V>Record<K, V>

Collections

OrderDto.cs — typesharp
OrderDto.cs
orderDto.ts
[TypeSharp]
public class OrderDto
{
    public List<string> Tags { get; set; }
    public Dictionary<string, int> Meta { get; set; }
    public IReadOnlyList<ItemDto> Items { get; set; }
}
/**
 * Auto-generated by TypeSharp
 * Do not edit this file manually
 */

export interface OrderDto {
    tags: string[];
    meta: Record<string, number>;
    items: readonly ItemDto[];
}
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1

Generic type parameters

Generic type parameters on classes and records are preserved in the TypeScript output.

ApiResponse.cs — typesharp
ApiResponse.cs
apiResponse.ts
[TypeSharp]
public class ApiResponse<T>
{
    public bool Success { get; set; }
    public string? Message { get; set; }
    T? Data { get; set; }
    public List<string> Errors { get; set; }
}
/**
 * Auto-generated by TypeSharp
 * Do not edit this file manually
 */

export interface ApiResponse<T> {
    success: boolean;
    message: string | null;
    data: T | null;
    errors: string[];
}
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1