// docs / records

Records

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

Positional records

ProductSummary.cs — typesharp
ProductSummary.cs
productSummary.ts
[TypeSharp]
public record ProductSummary(
    int Id,
    string Name,
    decimal Price,
    bool IsActive
);
/**
 * Auto-generated by TypeSharp
 * Do not edit this file manually
 */

export interface ProductSummary {
    id: number;
    name: string;
    price: number;
    isActive: boolean;
}
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1

record class and record struct

Both explicit record keywords are supported and treated identically.

records.cs — typesharp
records.cs
[TypeSharp]
public record class AddressRecord(string Street, string City, string PostalCode);

[TypeSharp]
public record struct CoordRecord(double Lat, double Lng);
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1

Body-only records

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

PersonRecord.cs — typesharp
PersonRecord.cs
personRecord.ts
[TypeSharp]
public record PersonRecord
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Age { get; set; }
}
/**
 * Auto-generated by TypeSharp
 * Do not edit this file manually
 */

export interface PersonRecord {
    firstName: string;
    lastName: string;
    age: number;
}
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1

Generic records

PagedResult.cs — typesharp
PagedResult.cs
pagedResult.ts
[TypeSharp]
public record PagedResult<T>(
    IEnumerable<T> Items,
    int TotalCount,
    int PageSize
);
/**
 * Auto-generated by TypeSharp
 * Do not edit this file manually
 */

export interface PagedResult<T> {
    items: T[];
    totalCount: number;
    pageSize: number;
}
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1

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.

SecureRecord.cs — typesharp
SecureRecord.cs
secureRecord.ts
[TypeSharp]
public record SecureRecord(
    string Name,
    [property: TypeIgnore] string Secret,
    [property: TypeAs("Date")] DateTime CreatedAt,
    [property: Obsolete("Use Name")] string Alias
);
/**
 * Auto-generated by TypeSharp
 * Do not edit this file manually
 */

export interface SecureRecord {
    name: string;
    createdAt: Date;
    /** @deprecated Use Name */
    alias: string;
}
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1