Skip to content

no-nullable

Id
@azure-tools/typespec-azure-core/no-nullable

Use ? for optional properties.

Properties are most often not nullable but optional. Do not use | null to specify that a property is nullable. Instead, use the ? operator to indicate that a property is optional.

  • Area: API, SDK

A nullable property is usually a mistake where an optional property was intended.

model Pet {
id: string;
owner: string | null;
}
model Pet {
id: string;
owner?: string;
}

Suppress only when required to match an existing API; otherwise use an optional property.