With new signal forms in 21, the documentation says I should be able to mark a form input as nullable. There's an example right here in there documentation https://angular.dev/guide/forms/signals/model-design#avoid-undefined
When I try that I'm getting a type error and I can't find the workaround:
import { Component, signal } from '@angular/core';
import { Field, form, required } from '@angular/forms/signals';
interface Entity {
name: string;
description: string | null;
}
@Component({
selector: 'bo-scaffold-label',
imports: [Field],
template: `
testing
`
})
export class ScaffoldLabel {
protected readonly entity = signal({
name: '',
description: null
});
protected readonly form = form(this.entity, (path) => {
required(path.name);
});
protected submit($event: Event) {
$event.preventDefault();
$event.stopPropagation();
console.log('submit', this.entity());
}
}
On the line with [field]="form.description" I get the error
TS2322: Type 'string | null' is not assignable to type 'string'. Type 'null' is not assignable to type 'string'.. Is there some setting in the tsconfig I'm missing?