TypeSharp is attribute-driven. Install TypeSharp.Attributes in your C# project to control which types are exported and how.
$ dotnet add package TypeSharp.Attributes [TypeSharp]Marks a class, record, or enum for TypeScript generation. Only decorated types are included — unannotated types are ignored entirely.
[TypeSharp] public class UserDto { } [TypeSharp] public record ProductSummary(int Id, string Name) { } [TypeSharp] public enum UserRole { Guest, Member, Admin }
[TypeSharp("name")]Overrides the generated TypeScript interface name.
[TypeSharp("auth_response")] public class AuthResponse { public string AccessToken { get; set; } public string RefreshToken { get; set; } }
export interface auth_response { accessToken: string; refreshToken: string; }
[TypeIgnore]Excludes a property from the generated output.
[TypeSharp] public class UserDto { public string Name { get; set; } [TypeIgnore] public string PasswordHash { get; set; } }
[TypeName("name")]Overrides the generated property name.
[TypeSharp] public class UserDto { [TypeName("created_at")] public DateTime CreatedAt { get; set; } }
[TypeAs("type")]Overrides the inferred TypeScript type for a property.
[TypeSharp] public class UserDto { [TypeAs("Date")] public DateTime UpdatedAt { get; set; } }
[Obsolete] Marks a property as deprecated. TypeSharp emits a /** @deprecated */ JSDoc comment on the generated TypeScript property.
[TypeSharp] public class UserDto { public string Email { get; set; } [Obsolete("Use Email instead.")] public string? Username { get; set; } }
export interface UserDto { email: string; /** @deprecated Use Email instead. */ username: string | null; }
On record primary constructor parameters, use the property: attribute target so the compiler applies the attribute to the generated property: [property: TypeIgnore], [property: TypeAs("Date")]. [Obsolete] works both with and without the prefix.