Skip to content

Commit 16b706b

Browse files
cexbrayatmhevery
authored andcommitted
docs: improve FormBuilder.group deprecation message (#39946)
This expands the deprecation message that started to pop up in v11.0.3 after the landing of commit e148382, that deprecated the `{[key: string]: any}` type for the options property of the `FormBuilder.group` method. It turns out that having a custom validator declared as `{ validators: (group: FormGroup) => ValidationErrors|null }` works in practice, but is now inferred by TS as the deprecated version of `group` (because `FormGroup` is a subclass of `AbstractControl` that `ValidatorFn` expects). We considered the possibility of tweaking the forms API to accept such validators, but it turns out to generate too many changes in the framework or possible breaking changes for Angular users. We settled for a more explicit deprecation message, elaborated with the help of @petebacondarwin. This will hopefully help developers to understand why the deprecation warning is showing up when they think they are already using the non-deprecated overload. PR Close #39946
1 parent 4aeb65d commit 16b706b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/forms/src/form_builder.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,14 @@ export class FormBuilder {
5454
* @description
5555
* Construct a new `FormGroup` instance.
5656
*
57-
* @deprecated This api is not typesafe and can result in issues with Closure Compiler renaming.
58-
* Use the `FormBuilder#group` overload with `AbstractControlOptions` instead.
57+
* @deprecated This API is not typesafe and can result in issues with Closure Compiler renaming.
58+
* Use the `FormBuilder#group` overload with `AbstractControlOptions` instead.
59+
* Note that `AbstractControlOptions` expects `validators` and `asyncValidators` to be valid
60+
* validators. If you have custom validators, make sure their validation function parameter is
61+
* `AbstractControl` and not a sub-class, such as `FormGroup`. These functions will be called with
62+
* an object of type `AbstractControl` and that cannot be automatically downcast to a subclass, so
63+
* TypeScript sees this as an error. For example, change the `(group: FormGroup) =>
64+
* ValidationErrors|null` signature to be `(group: AbstractControl) => ValidationErrors|null`.
5965
*
6066
* @param controlsConfig A collection of child controls. The key for each child is the name
6167
* under which it is registered.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy