Skip to content

FormBuilder does not support nulls in strictNullChecks mode #186

@undsoft

Description

@undsoft

Is this a regression?

No

Description

  1. Enable strictNullChecks.
  constructor(
    private fb: FormBuilder
  ) {}

  protected readonly noBueno = this.fb.group({
    age: [null as string | null],
    //    ^^^^^^^^^^^^^^^^^ TS2322: Type string | null is not assignable to type string
  });

  protected readonly bueno = new FormGroup({
    age: new FormControl(null as string | null),
    // This works.
  });

Another somewhat related issue is that by virtue of extending Angular's form builder, FormBuilder has nonNullable property that returns native Angular implementation and lacks extra functionality from @ngneat/reactive-forms.
This can be confusing when someone is migrating to strictNullChecks and is actively converting form by adding nonNullable to them.

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw


Please provide the environment you discovered this bug in


Anything else?

Angular 19.0.0
Typescript 5.6.2
@ngneat/reactive-forms 5.0.2

Do you want to create a pull request?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions