From 7ee121f595a47338b31098ae51a6f91d80c8fdce Mon Sep 17 00:00:00 2001 From: Dylan Hunn Date: Fri, 25 Feb 2022 09:47:45 -0800 Subject: [PATCH] feat(forms): Add untyped versions of the model classes for use in migration. (#45205) We had previously introduced an `AnyForUntypedForms` type alias. However, given our updated migration plan, we actually want to use aliases for the model classes themselves. This commit introduces these aliases, and adds them to the public API. It must be merged before the types, in order to migrate google3. PR Close #45205 --- goldens/public-api/forms/forms.md | 21 ++++++++-- packages/forms/src/forms.ts | 18 +-------- packages/forms/src/model.ts | 64 +++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 20 deletions(-) diff --git a/goldens/public-api/forms/forms.md b/goldens/public-api/forms/forms.md index 63753d59fba..3fbadbf5836 100644 --- a/goldens/public-api/forms/forms.md +++ b/goldens/public-api/forms/forms.md @@ -143,9 +143,6 @@ export class AbstractFormGroupDirective extends ControlContainer implements OnIn static ɵfac: i0.ɵɵFactoryDeclaration; } -// @public -export type AnyForUntypedForms = any; - // @public export interface AsyncValidator extends Validator { validate(control: AbstractControl): Promise | Observable; @@ -725,6 +722,24 @@ export class SelectMultipleControlValueAccessor extends BuiltInControlValueAcces static ɵfac: i0.ɵɵFactoryDeclaration; } +// @public +export type UntypedFormArray = FormArray; + +// @public (undocumented) +export const UntypedFormArray: UntypedFormArrayCtor; + +// @public +export type UntypedFormControl = FormControl; + +// @public (undocumented) +export const UntypedFormControl: UntypedFormControlCtor; + +// @public +export type UntypedFormGroup = FormGroup; + +// @public (undocumented) +export const UntypedFormGroup: UntypedFormGroupCtor; + // @public export type ValidationErrors = { [key: string]: any; diff --git a/packages/forms/src/forms.ts b/packages/forms/src/forms.ts index 4eefc1b1c36..17c10d873ba 100644 --- a/packages/forms/src/forms.ts +++ b/packages/forms/src/forms.ts @@ -42,24 +42,8 @@ export {NgSelectOption, SelectControlValueAccessor} from './directives/select_co export {SelectMultipleControlValueAccessor, ɵNgSelectMultipleOption} from './directives/select_multiple_control_value_accessor'; export {AsyncValidator, AsyncValidatorFn, CheckboxRequiredValidator, EmailValidator, MaxLengthValidator, MaxValidator, MinLengthValidator, MinValidator, PatternValidator, RequiredValidator, ValidationErrors, Validator, ValidatorFn} from './directives/validators'; export {FormBuilder} from './form_builder'; -export {AbstractControl, AbstractControlOptions, FormArray, FormControl, FormControlOptions, FormControlStatus, FormGroup, ɵFormControlCtor} from './model'; +export {AbstractControl, AbstractControlOptions, FormArray, FormControl, FormControlOptions, FormControlStatus, FormGroup, UntypedFormArray, UntypedFormControl, UntypedFormGroup, ɵFormControlCtor} from './model'; export {NG_ASYNC_VALIDATORS, NG_VALIDATORS, Validators} from './validators'; export {VERSION} from './version'; -/** - * `AnyForUntypedForms` is an alias for `any` used as part of the typed forms - * migration. - * - * `AnyForUntypedForms` was inserted into your code automatically as part of a migration. To - * continue opting out of strong types, simply replace it with `any`. To opt-in to typed forms, - * remove - * `` from your call site. - * - * This symbol is currently unused. Please do not use it. These docs will be updated when this - * symbol is in use. - * - * @publicApi - */ -export type AnyForUntypedForms = any; - export * from './form_providers'; diff --git a/packages/forms/src/model.ts b/packages/forms/src/model.ts index 9703a03d8ab..1088d4660e6 100644 --- a/packages/forms/src/model.ts +++ b/packages/forms/src/model.ts @@ -1594,6 +1594,28 @@ export const FormControl: ɵFormControlCtor = } }); +interface UntypedFormControlCtor { + new(): UntypedFormControl; + + new(formState?: any, validatorOrOpts?: ValidatorFn|ValidatorFn[]|FormControlOptions|null, + asyncValidator?: AsyncValidatorFn|AsyncValidatorFn[]|null): UntypedFormControl; + + /** + * The presence of an explicit `prototype` property provides backwards-compatibility for apps that + * manually inspect the prototype chain. + */ + prototype: FormControl; +} + +/** + * UntypedFormControl is a non-strongly-typed version of @see FormControl. + * Note: this is used for migration purposes only. Please avoid using it directly in your code and + * prefer `FormControl` instead, unless you have been migrated to it automatically. + */ +export type UntypedFormControl = FormControl; + +export const UntypedFormControl: UntypedFormControlCtor = FormControl; + /** * Tracks the value and validity state of a group of `FormControl` instances. * @@ -2042,6 +2064,27 @@ export class FormGroup extends AbstractControl { } } +interface UntypedFormGroupCtor { + new(controls: {[key: string]: AbstractControl}, + validatorOrOpts?: ValidatorFn|ValidatorFn[]|AbstractControlOptions|null, + asyncValidator?: AsyncValidatorFn|AsyncValidatorFn[]|null): UntypedFormGroup; + + /** + * The presence of an explicit `prototype` property provides backwards-compatibility for apps that + * manually inspect the prototype chain. + */ + prototype: FormGroup; +} + +/** + * UntypedFormGroup is a non-strongly-typed version of @see FormGroup. + * Note: this is used for migration purposes only. Please avoid using it directly in your code and + * prefer `FormControl` instead, unless you have been migrated to it automatically. + */ +export type UntypedFormGroup = FormGroup; + +export const UntypedFormGroup: UntypedFormGroupCtor = FormGroup; + /** * Tracks the value and validity state of an array of `FormControl`, * `FormGroup` or `FormArray` instances. @@ -2506,3 +2549,24 @@ export class FormArray extends AbstractControl { return this.at(name as number) ?? null; } } + +interface UntypedFormArrayCtor { + new(controls: AbstractControl[], + validatorOrOpts?: ValidatorFn|ValidatorFn[]|AbstractControlOptions|null, + asyncValidator?: AsyncValidatorFn|AsyncValidatorFn[]|null): UntypedFormArray; + + /** + * The presence of an explicit `prototype` property provides backwards-compatibility for apps that + * manually inspect the prototype chain. + */ + prototype: FormArray; +} + +/** + * UntypedFormArray is a non-strongly-typed version of @see FormArray. + * Note: this is used for migration purposes only. Please avoid using it directly in your code and + * prefer `FormControl` instead, unless you have been migrated to it automatically. + */ +export type UntypedFormArray = FormArray; + +export const UntypedFormArray: UntypedFormArrayCtor = FormArray;