Skip to content

validateAsync does not allow undefined value to be returned #67859

@WillBoig

Description

@WillBoig

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

forms

Is this a regression?

Yes

Description

Angular documentation states that when using validateAsync : The params function runs on every value change. Return undefined to skip validation. The factory function runs once during setup and receives params as a signal. The resource updates automatically when params change.

Im my experience, return undefined in the params of validateAsync is not allowed and produces the error stated below.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/vsbu7e1k-wjjrqne7?file=src%2Fapp%2Fuser.validator.ts

Please provide the exception or error you saw

TS2322: Type '({ value }: RootFieldContext<string>) => string | undefined' is not assignable to type '(ctx: RootFieldContext<string>) => string'.
  Type 'string | undefined' is not assignable to type 'string'.
    Type 'undefined' is not assignable to type 'string'.

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

Angular CLI       : 21.2.3
Node.js           : 22.21.1
Package Manager   : npm 10.9.4
Operating System  : win32 x64

"@angular/cdk": "^21.2.3"
"@angular/common": "21.2.5"
"@angular/compiler": "21.2.5"
"@angular/core": "21.2.5"
"@angular/forms": "21.2.5"
"@angular/material": "^21.2.0-next"
"@angular/platform-browser": "21.2.5"
"@angular/build": "21.2.3"
"@angular/cli": "21.2.3"
"@angular/compiler-cli": "21.2.5"

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions