Skip to content

Error TS2322 with custom form control and input called min #69624

Closed as duplicate

Description

@jeripeierSBB

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

forms

Is this a regression?

No

Description

When implementing ControlValueAccessor for a custom form control and this form component also has an input called min or max, there is a compiler error complaining about a type mismatch (see below) when used with Signal Forms. In my eyes the error is wrong.
To reproduce, open the StackBlitz example.
If the input has another name or is removed, compiling does work.

Workaround:
Wrap the formField assignment with $any(): [formField]=$any(form.control).

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-nz2vatce?file=src%2Fmain.ts

Please provide the exception or error you saw

✘ [ERROR] TS2322: Type 'Date | undefined' is not assignable to type 'Date | null'.
  Type 'undefined' is not assignable to type 'Date | null'. [plugin angular-compiler]

    src/main.ts:34:31:
      34 │ ...mplate: `<app-date-picker [formField]="form.date"></app-date-pi...
         ╵                               ~~~~~~~~~

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

Angular CLI       : 22.0.5
Angular           : 22.0.5
Node.js           : 22.22.3
Package Manager   : npm 10.8.2
Operating System  : linux x64

┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package                   │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build            │ 22.0.5            │ ^22.0.0           │
│ @angular/cli              │ 22.0.5            │ ^22.0.0           │
│ @angular/common           │ 22.0.5            │ ^22.0.0           │
│ @angular/compiler         │ 22.0.5            │ ^22.0.0           │
│ @angular/compiler-cli     │ 22.0.5            │ ^22.0.0           │
│ @angular/core             │ 22.0.5            │ ^22.0.0           │
│ @angular/forms            │ 22.0.5            │ ^22.0.0           │
│ @angular/platform-browser │ 22.0.5            │ ^22.0.0           │
│ @angular/router           │ 22.0.5            │ ^22.0.0           │
│ rxjs                      │ 7.8.2             │ ^7.8.1            │
│ typescript                │ 6.0.3             │ ^6.0.3            │
└───────────────────────────┴───────────────────┴───────────────────┘

Anything else?

No response

Activity

  1. added this to the needsTriage milestone on Jul 2, 2026
  2. added this to the needsTriage milestone on Jul 2, 2026
  3. imaksp commented on Jul 2, 2026

    @imaksp
    Contributor

    It works if you use Date | undefined instead of Date | null, so related to null usage with signal forms,
    I had tried with older version for string | null here #66570,
    but they said its being tracked here (its closed now):
    #65454

  4. jeripeierSBB commented on Jul 2, 2026

    @jeripeierSBB
    ContributorAuthor

    It works if you use Date | undefined instead of Date | null, so related to null usage with signal forms, I had tried with older version for string | null here #66570, but they said its being tracked here (its closed now): #65454

    It works if you change the type of min to Date | undefined. The issue is that if the Control Value Accessor component lives in a library, you can't simply change its types.
    Casting to "Date | undefined" on the consuming component (in signal model) doesn't work.

  5. JeanMeche commented on Jul 3, 2026

    @JeanMeche
    Member

    This is because of the definition of min on ReadonlyFieldState : https://angular.dev/api/forms/signals/ReadonlyFieldState#min

    I'd consider that the limit of the interop between the CVA and FormFields. The interface will need to match because this is what the FieldState exposed.

  6. imaksp commented on Jul 6, 2026

    @imaksp
    Contributor

    This is because of the definition of min on ReadonlyFieldState : https://angular.dev/api/forms/signals/ReadonlyFieldState#min

    I'd consider that the limit of the interop between the CVA and FormFields. The interface will need to match because this is what the FieldState exposed.

    Ok, so adding | null to ReadonlyFieldState type (like Signal<NonNullable<TValue> | undefined | null>) will fix this or not?

  7. jeripeierSBB commented on Jul 6, 2026

    @jeripeierSBB
    ContributorAuthor

    Ok, I understand. In our case having #69452 would also improve the situation.

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

    Sponsor
    SponsoredKunjungi sekarang
    Promo