Hi
I am getting getting error on these 2 fields startAT,EndAt. Using Angular 17.
TypeScript
export class DateRangeValidatorDirective implements Validator {
validate(control: AbstractControl): ValidationErrors | null {
const start: Date = control.get('startAt').value;
const end: Date = control.get('endAt').value;
if (start && end) {
const isRangeValid = end.getTime() - start.getTime() > 0;
return isRangeValid ? null : { dateRange: true };
}
return null;
}
}Thanks

Dharmeshwaran SRank #819 · 2.8K reputationPosted Jun 27, 2024, 10:00 AM EDT
To resolve the error "Object is possibly NULL" in your code, you need to ensure that the values you are accessing are not null. TypeScript is strict about null checking, so you should include additional checks to handle these potential null values.