CHR0012: Event types should avoid nullable properties
Rule Description
Section titled “Rule Description”Event types can contain nullable properties, but this is often an anti-pattern in event sourcing. A nullable field can hide multiple meanings in one event. Prefer expressing optional facts with a dedicated event type when possible.
Severity
Section titled “Severity”Warning
Example
Section titled “Example”Warning
Section titled “Warning”using Cratis.Chronicle.Events;
[EventType]public record MissionAccepted( string MissionId, DateOnly? StartDate);Preferred
Section titled “Preferred”using Cratis.Chronicle.Events;
[EventType]public record MissionAccepted( string MissionId, DateOnly StartDate);
[EventType]public record MissionAcceptedWithoutStartDate( string MissionId);Why This Rule Exists
Section titled “Why This Rule Exists”Events represent immutable facts. Nullable properties can blur the meaning of those facts and force consumers to branch on missing values.
Keeping event types explicit:
- improves readability
- reduces ambiguity for projections, reducers, and reactors
- keeps event history easier to understand
Related Rules
Section titled “Related Rules”- CHR0001: Event sequence append operations