// docs / nullable-types

Nullable Types

TypeSharp handles both nullable value types (int?) and nullable reference types (string?) — mapping both to T | null in TypeScript.

Example

ProfileDto.cs — typesharp
ProfileDto.cs
profileDto.ts
[TypeSharp]
public class ProfileDto
{
    public string Name { get; set; }        // non-nullable
    public string? Bio { get; set; }       // nullable reference
    public int Age { get; set; }          // non-nullable
    public int? Score { get; set; }       // nullable value
    public DateTime? DeletedAt { get; set; }
}
/**
 * Auto-generated by TypeSharp
 * Do not edit this file manually
 */

export interface ProfileDto {
    name: string;
    bio: string | null;
    age: number;
    score: number | null;
    deletedAt: string | null;
}
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1

Long form — Nullable<T>

Nullable<T> is handled identically to T? — both map to T | null.

example.cs — typesharp
example.cs
example.ts
[TypeSharp]
public class ExampleDto
{
    public Nullable<int> Score { get; set; }     // long form
    public int? Rank { get; set; }                // short form
}
/**
 * Auto-generated by TypeSharp
 * Do not edit this file manually
 */

export interface ExampleDto {
    score: number | null;
    rank: number | null;
}
⎇ main✓ Prettier
csharpUTF-8Ln 1, Col 1