C# attributes for controlling TypeSharp TypeScript generation.
TypeSharp is a direct C# → TypeScript type generator. This package provides the attributes that let you fine-tune what gets generated and how — without touching the CLI config.
dotnet add package TypeSharp.Attributes| Attribute | Target | Description |
|---|---|---|
[TypeSharp] |
(Class/Enum) | Marks a class or enum to be included in TypeScript generation |
[TypeIgnore] |
Property | Excludes the property from TypeScript output |
[TypeName("...")] |
Property | Overrides the property name in the generated TypeScript |
[TypeAs("...")] |
Property | Overrides the inferred TypeScript type |
[Obsolete("...")] |
Property | Marks a property as obsolete and optionally affects TypeScript type output |
Exclude a property entirely from the generated output.
using TypeSharp.Attributes;
[TypeSharp]
public class UserDto
{
public string Email { get; set; }
[TypeIgnore]
public string PasswordHash { get; set; }
}Generated TypeScript:
export interface UserDto {
email: string;
}Override the property name in the generated TypeScript output.
[TypeSharp]
public class UserDto
{
[TypeName("created_at")]
public DateTime CreatedAt { get; set; }
[TypeName("updated_at")]
public DateTime UpdatedAt { get; set; }
}Generated TypeScript:
export interface UserDto {
created_at: string;
updated_at: string;
}Override the inferred TypeScript type for a property.
[TypeSharp]
public class UserDto
{
[TypeAs("Date")]
public DateTime CreatedAt { get; set; }
[TypeAs("'admin' | 'user' | 'guest'")]
public string Role { get; set; }
}Generated TypeScript:
export interface UserDto {
createdAt: Date;
role: "admin" | "user" | "guest";
}All three attributes can be stacked together or alongside [Obsolete].
[TypeSharp]
public class ProductDto
{
public Guid Id { get; set; }
[TypeName("display_name")]
public string Name { get; set; }
[TypeAs("'active' | 'inactive'")]
public string Status { get; set; }
[TypeIgnore]
public string InternalCode { get; set; }
[Obsolete("Use Status instead.")]
public bool IsActive { get; set; }
}Generated TypeScript:
export interface ProductDto {
id: string;
display_name: string;
status: "active" | "inactive";
/** @deprecated Use Status instead. */
isActive: boolean;
}- .NET 10.0x
- TypeSharp CLI
>= 0.1.1
- TypeSharp CLI (npm) — the generator that reads these attributes
- TypeSharp GitHub — source, docs, and issue tracker
MIT © Siyavuya Chagi
Built with ❤️ in South Africa 🇿🇦