TypeSharp maps C# generic collections and types to their TypeScript equivalents.
| 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> |
[TypeSharp] public class OrderDto { public List<string> Tags { get; set; } public Dictionary<string, int> Meta { get; set; } public IReadOnlyList<ItemDto> Items { get; set; } }
Generic type parameters on classes and records are preserved in the TypeScript output.
[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; } }