// docs / records

Records

TypeSharp supports all C# record forms. Records are emitted as TypeScript interfaces, identical to classes.

Positional records

[C#]
[TypeSharp]
public record ProductSummary(
    int Id,
    string Name,
    decimal Price,
    bool IsActive
);
[TS]
export interface ProductSummary {
  id: number;
  name: string;
  price: number;
  isActive: boolean;
}

record class and record struct

Both explicit record keywords are supported and treated identically.

[TypeSharp]
public record class AddressRecord(string Street, string City, string PostalCode);

[TypeSharp]
public record struct CoordRecord(double Lat, double Lng);

Body-only records

Records without a primary constructor are parsed from their { get; set; } properties, the same way as classes.

[TypeSharp]
public record PersonRecord
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

Generic records

[C#]
[TypeSharp]
public record PagedResult<T>(
    IEnumerable<T> Items,
    int TotalCount,
    int PageSize
);
[TS]
export interface PagedResult<T> {
  items: T[];
  totalCount: number;
  pageSize: number;
}

Per-parameter attribute overrides

[TypeIgnore], [TypeName], [TypeAs], and [Obsolete] work on primary constructor parameters. Use the property: target so the compiler applies the attribute to the generated property.

[C#]
[TypeSharp]
public record SecureRecord(
    string Name,
    [property: TypeIgnore] string Secret,
    [property: TypeAs("Date")] DateTime CreatedAt,
    [property: Obsolete("Use Name")] string Alias
);
[TS]
export interface SecureRecord {
  name: string;
  createdAt: Date;
  /** @deprecated Use Name */
  alias: string;
}