// docs / inheritance

Inheritance

TypeSharp resolves class hierarchies and maps them to TypeScript extends. Base classes are emitted as separate interface files and referenced by name.

Example

UserDto.cs — typesharp
UserDto.cs
baseEntity.ts
userDto.ts
[TypeSharp]
public class BaseEntity
{
    public int Id { get; set; }
    public DateTime CreatedAt { get; set; }
}

[TypeSharp]
public class UserDto : BaseEntity
{
    public string Name { get; set; }
    public string? Email { get; set; }
}
/**
 * Auto-generated by TypeSharp
 * Do not edit this file manually
 */

export interface BaseEntity {
    id: number;
    createdAt: string;
}
import type { BaseEntity } from './baseEntity';
/**
 * Auto-generated by TypeSharp
 * Do not edit this file manually
 */

export interface UserDto extends BaseEntity {
    name: string;
    email: string | null;
}
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1

Multi-level inheritance

Full inheritance chains are resolved — each level gets its own interface file.

models.cs — typesharp
models.cs
output.ts
[TypeSharp]
public class Entity
{
    public int Id { get; set; }
}

[TypeSharp]
public class AuditableEntity : Entity
{
    public DateTime CreatedAt { get; set; }
    public DateTime UpdatedAt { get; set; }
}

[TypeSharp]
public class UserDto : AuditableEntity
{
    public string Name { get; set; }
    public string Email { get; set; }
}
export interface Entity {
    id: number;
}

export interface AuditableEntity extends Entity {
    createdAt: string;
    updatedAt: string;
}

export interface UserDto extends AuditableEntity {
    name: string;
    email: string;
}
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1

C# interface filtering

Any base type matching the C# interface convention (I + uppercase letter) is automatically stripped from the inheritance chain.

PaymentResult.cs — typesharp
PaymentResult.cs
paymentResult.ts
[TypeSharp]
public class PaymentResult : BaseResult, IActionResult, IDisposable
{
    public bool Paid { get; set; }
}
// IActionResult and IDisposable are automatically filtered out

export interface PaymentResult extends BaseResult {
    paid: boolean;
}
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1

Notes

  • Multi-level inheritance chains are fully resolved.
  • Abstract base classes are emitted as regular interfaces.
  • C# interface implementations (IEntity, IDisposable) are automatically filtered — only class inheritance is mapped.