← 输入框|github.com|刷新
Skip to content

Signal Forms coerce null to numeric value on text inputs ( <input type="text"> ) in v22 #69757

Open

Description

@xMikee

Which @angular/* package(s) are the source of the bug?

forms

Is this a regression?

Yes

Description

When using Signal Forms in Angular v22 with a standard text input (e.g., ), if the model's value is
programmatically set to null (or receives null as an initial/updated value), the form control incorrectly treats/coerces this value
as a numeric type instead of remaining null or an empty string.
This is a regression, as the exact same implementation worked correctly and preserved the expected text/null type in Angular v21. This
is particularly noticeable on typed string fields or generic text fields where passing null unexpectedly alters the
value type.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-dv7tq7dq

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)

Angular CLI       : 22.0.0
Angular           : 22.0.0
Node.js           : 26.0.0
Package Manager   : npm 11.12.1
Operating System  : darwin arm64

┌───────────────────────────────────┬───────────────────┬───────────────────┐
│ Package                           │ Installed Version │ Requested Version │
├───────────────────────────────────┼───────────────────┼───────────────────┤
│ @angular-devkit/architect         │ 0.2200.0          │ ^0.2200.0         │
│ @angular-devkit/core              │ 22.0.0            │ ^22.0.0           │
│ @angular/build                    │ 22.0.0            │ ^22.0.0           │
│ @angular/cdk                      │ 21.2.8            │ ^21.2.8           │
│ @angular/cli                      │ 22.0.0            │ ^22.0.0           │
│ @angular/common                   │ 22.0.0            │ ^22.0.0           │
│ @angular/compiler                 │ 22.0.0            │ ^22.0.0           │
│ @angular/compiler-cli             │ 22.0.0            │ ^22.0.0           │
│ @angular/core                     │ 22.0.0            │ ^22.0.0           │
│ @angular/forms                    │ 22.0.0            │ ^22.0.0           │
│ @angular/platform-browser         │ 22.0.0            │ ^22.0.0           │
│ @angular/platform-browser-dynamic │ 22.0.0            │ ^22.0.0           │
│ @angular/router                   │ 22.0.0            │ ^22.0.0           │
│ ng-packagr                        │ 22.0.0            │ ^22.0.0           │
│ rxjs                              │ 7.8.2             │ ~7.8.0            │
│ typescript                        │ 6.0.3             │ ~6.0.3            │
│ vitest                            │ 4.1.5             │ ^4.0.8            │
└───────────────────────────────────┴───────────────────┴───────────────────┘

Anything else?

No response

Activity

  1. added this to the needsTriage milestone on Jul 13, 2026
  2. hawkgs commented on Jul 13, 2026

    @hawkgs
    Member

    @xMikee, I took a look at your StackBlitz demo, but I am not sure I found an issue in it.

    • this.form.isbn() is FieldState<string | null, string>, which is expected
    • When I submit an empty input, the result is { "isbn": null }

    Your test-field component accepts a field input with a wide range of types (string | number | boolean | null).

  3. MeAkib commented on Jul 13, 2026

    @MeAkib
    Contributor

    You'll get some info here

  4. xMikee commented on Jul 13, 2026

    @xMikee
    Author

    Just to confirm: if I receive a null string field from the backend, do I have to map it to the signal as an empty string? Otherwise, the behavior is what I’ve attached—meaning the form doesn't validate the field correctly.
    Image

  5. JeanMeche commented on Jul 13, 2026

    @JeanMeche
    Member

    Having a dynamic input type comes with some caveats. Typechecking won't be able to pick up that null issue (as the type is equivalent to any). Maybe in this case we should at least log a runtime warning when a text input recieves a null value.

  6. reopened this on Jul 13, 2026
  7. hawkgs commented on Jul 13, 2026

    @hawkgs
    Member

    do I have to map it to the signal as an empty string

    Yes. Please ignore my initial comment. This should be relevant: https://angular.dev/guide/forms/signals/models#initializing-all-fields (HELPFUL tip).

    Indeed, in your case the input type of test-input masks the issue so you don't get an error (we should probably have a runtime one as Matthieu pointed).

  8. AdamSheaffer commented on Jul 13, 2026

    @AdamSheaffer

    I'd also recommend updating this section of the documentation to include this gotcha https://angular.dev/guide/forms/signals/models#example-loading-data-from-an-api

    More often than not, data returned from API's will likely contain nullable strings, so I suspect developers will need to be guided towards the pattern of regularly creating new types for form objects and mapping them to/from their API models

  9. JeanMeche commented on Jul 13, 2026

    @JeanMeche
    Member

    More often than not, data returned from API's will likely contain nullable strings, so I suspect developers will need to be guided towards the pattern of regularly creating new types for form objects and mapping them to/from their API models

    This is a parsing issue though. This should be caught correctly by for example, relying on schema validation (zod, valibot etc).

  10. AdamSheaffer commented on Jul 13, 2026

    @AdamSheaffer

    This is a parsing issue though. This should be caught correctly by for example, relying on schema validation (zod, valibot etc).

    This is a good message to put in the documentation

  11. wartab commented on Sep 2, 2026

    @wartab
    Contributor

    We were just bitten by this as well.
    I think falling back to strings or (if possible) to a sensible type for the input-type for null values would make sense to avoid breaking unexpected cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions