// docs / nullable-types

Nullable Types

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

C# input

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; }
}

TypeScript output

export interface ProfileDto {
    name: string;
    bio: string | null;
    age: number;
    score: number | null;
    deletedAt: string | null;
}

Notes

  • Requires <Nullable>enable</Nullable> in your .csproj for reference type nullability to be detected.
  • Without nullable context enabled, all reference types are treated as non-nullable.
  • Nullable<T> (long form) is also handled identically to T?.