-
Notifications
You must be signed in to change notification settings - Fork 26.2k
fix(forms): typed argument for FormBuilder group #26985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f22fba3
to
1d25da2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kara can you take a look too please? Thanks
packages/forms/src/form_builder.ts
Outdated
validators = legacyOrOpts.validators != null ? legacyOrOpts.validators : null; | ||
asyncValidators = | ||
legacyOrOpts.asyncValidators != null ? legacyOrOpts.asyncValidators : null; | ||
updateOn = legacyOrOpts.updateOn != null ? legacyOrOpts.updateOn : undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need all the ternary operator checks? Couldn't we use object destructuring instead? It seems that we are doing a lot of work no obvious reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To support the legacy options of shape
{
asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null;
validator?: ValidatorFn | ValidatorFn[] | null;
}
as well as AbstractControlOptions
with similar but slightly differently named properties (notice the ending s)
{
asyncValidators?: AsyncValidatorFn | AsyncValidatorFn[] | null;
validators?: ValidatorFn | ValidatorFn[] | null;
updateOn?: 'change' | 'blur' | 'submit';
}
packages/forms/src/form_builder.ts
Outdated
FormGroup { | ||
group( | ||
controlsConfig: {[key: string]: any}, | ||
legacyOrOpts: AbstractControlOptions|{[key: string]: any}|null = null): FormGroup { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm now realizing that this param name is very confusing. I think we should just call it options and document that it has two shapes one of which is deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me
@@ -205,7 +205,7 @@ export declare class FormBuilder { | |||
control(formState: any, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl; | |||
group(controlsConfig: { | |||
[key: string]: any; | |||
}, legacyOrOpts?: { | |||
}, legacyOrOpts?: AbstractControlOptions | { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this. Change. At minimum from docs perspective it makes the api cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, in terms of types, there isn't really a difference, but I do think this is helpful documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IgorMinar Should legacyOrOpts
be replaced with options
here, too?
@kara Note that type declarations were previously made less strict because of internal Google tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (once Igor's comments are addressed)
packages/forms/src/form_builder.ts
Outdated
FormGroup { | ||
group( | ||
controlsConfig: {[key: string]: any}, | ||
legacyOrOpts: AbstractControlOptions|{[key: string]: any}|null = null): FormGroup { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me
1d25da2
to
fac1fdb
Compare
@kara Thank you for your review. I renamed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just casual nitpicking following up on the legacyOrOpts
-> options
change.
packages/forms/src/form_builder.ts
Outdated
updateOn = legacyOrOpts.updateOn != null ? legacyOrOpts.updateOn : undefined; | ||
if (options != null) { | ||
if (isAbstractControlOptions(options)) { | ||
// `legacyOrOpts` are `AbstractControlOptions` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
legacyOrOpts
should also be replaced in the comment here since it was renamed to options
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, thanks for catching that. I fixed.
packages/forms/src/form_builder.ts
Outdated
asyncValidators = options.asyncValidators != null ? options.asyncValidators : null; | ||
updateOn = options.updateOn != null ? options.updateOn : undefined; | ||
} else { | ||
// `legacyOrOpts` are legacy form group options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above.
@@ -205,7 +205,7 @@ export declare class FormBuilder { | |||
control(formState: any, validatorOrOpts?: ValidatorFn | ValidatorFn[] | AbstractControlOptions | null, asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[] | null): FormControl; | |||
group(controlsConfig: { | |||
[key: string]: any; | |||
}, legacyOrOpts?: { | |||
}, legacyOrOpts?: AbstractControlOptions | { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@IgorMinar Should legacyOrOpts
be replaced with options
here, too?
fac1fdb
to
00feb89
Compare
00feb89
to
60824ff
Compare
Please note my comment and make sure that you don't recreate the issue that broke your internal Google tests, @kara and @IgorMinar This is the reason types were made less strict and correct. |
@LayZeeDK This PR does not actually make any meaningful type changes because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@IgorMinar Can you take another look? |
So Angular 7.1.0 landed. This will be in which version now? 7.2.0? 7.1.x? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm. Thanks for being patient!
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
The refactored
group
method ofFormBuilder
introduced by #24599 allows two types of options but the signature doesn't show it.What is the new behavior?
It adds a stricter type to the refactored
group
method.Does this PR introduce a breaking change?
Other information
cc @kara