// 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>

Example

[C#]
public class OrderDto
{
  public List<string> Tags;
  public Dictionary<string, int> Meta;
  public IReadOnlyList<ItemDto> Items;
}
[TS]
export interface OrderDto {
  tags: string[];
  meta: Record<string, number>;
  items: readonly ItemDto[];
}