TypeSharp.Attributes
1.0.0
See the version list below for details.
dotnet add package TypeSharp.Attributes --version 1.0.0
NuGet\Install-Package TypeSharp.Attributes -Version 1.0.0
<PackageReference Include="TypeSharp.Attributes" Version="1.0.0" />
<PackageVersion Include="TypeSharp.Attributes" Version="1.0.0" />
<PackageReference Include="TypeSharp.Attributes" />
paket add TypeSharp.Attributes --version 1.0.0
#r "nuget: TypeSharp.Attributes, 1.0.0"
#:package TypeSharp.Attributes@1.0.0
#addin nuget:?package=TypeSharp.Attributes&version=1.0.0
#tool nuget:?package=TypeSharp.Attributes&version=1.0.0
TypeSharp.Attributes
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.
Installation
dotnet add package TypeSharp.Attributes
Attributes
| Attribute | Target | Description |
|---|---|---|
[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 |
Usage
[TypeIgnore]
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;
}
[TypeName("...")]
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;
}
[TypeAs("...")]
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';
}
Combining attributes
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;
}
Requirements
- .NET Standard 2.0 or later
- TypeSharp CLI
>= 0.1.1
Related
- TypeSharp CLI (npm) — the generator that reads these attributes
- TypeSharp GitHub — source, docs, and issue tracker
License
MIT © Siyavuya Chagi
Built with ❤️ in South Africa 🇿🇦
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.