Skip to content

Commit b9577ad

Browse files
JeanMechealxhub
authored andcommitted
refactor(forms): cleanup type any in forms tests (angular#48624)
Removing every type any in forms with a reference to angular#9100 PR Close angular#48624
1 parent cb6d73a commit b9577ad

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

packages/forms/test/directives_spec.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,14 @@ class CustomValidatorDirective implements Validator {
112112

113113
describe('composeValidators', () => {
114114
it('should compose functions', () => {
115-
const dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
116-
const dummy2 = (_: any /** TODO #9100 */) => ({'dummy2': true});
115+
const dummy1 = () => ({'dummy1': true});
116+
const dummy2 = () => ({'dummy2': true});
117117
const v = composeValidators([dummy1, dummy2])!;
118118
expect(v(new FormControl(''))).toEqual({'dummy1': true, 'dummy2': true});
119119
});
120120

121121
it('should compose validator directives', () => {
122-
const dummy1 = (_: any /** TODO #9100 */) => ({'dummy1': true});
122+
const dummy1 = () => ({'dummy1': true});
123123
const v = composeValidators([dummy1, new CustomValidatorDirective()])!;
124124
expect(v(new FormControl(''))).toEqual({'dummy1': true, 'custom': true});
125125
});
@@ -309,10 +309,10 @@ class CustomValidatorDirective implements Validator {
309309
});
310310

311311
describe('NgForm', () => {
312-
let form: any /** TODO #9100 */;
312+
let form: NgForm;
313313
let formModel: FormGroup;
314-
let loginControlDir: any /** TODO #9100 */;
315-
let personControlGroupDir: any /** TODO #9100 */;
314+
let loginControlDir: NgModel;
315+
let personControlGroupDir: NgModelGroup;
316316

317317
beforeEach(() => {
318318
form = new NgForm([], []);
@@ -384,7 +384,7 @@ class CustomValidatorDirective implements Validator {
384384
});
385385

386386
it('should set up sync validator', fakeAsync(() => {
387-
const formValidator = (c: any /** TODO #9100 */) => ({'custom': true});
387+
const formValidator = () => ({'custom': true});
388388
const f = new NgForm([formValidator], []);
389389

390390
tick();
@@ -402,8 +402,8 @@ class CustomValidatorDirective implements Validator {
402402
});
403403

404404
describe('FormGroupName', () => {
405-
let formModel: any /** TODO #9100 */;
406-
let controlGroupDir: any /** TODO #9100 */;
405+
let formModel: FormGroup;
406+
let controlGroupDir: FormGroupName;
407407

408408
beforeEach(() => {
409409
formModel = new FormGroup({'login': new FormControl(null)});
@@ -481,9 +481,9 @@ class CustomValidatorDirective implements Validator {
481481
});
482482

483483
describe('FormControlDirective', () => {
484-
let controlDir: any /** TODO #9100 */;
485-
let control: any /** TODO #9100 */;
486-
const checkProperties = function(control: AbstractControl) {
484+
let controlDir: FormControlDirective;
485+
let control: FormControl;
486+
const checkProperties = function(control: FormControl) {
487487
expect(controlDir.control).toBe(control);
488488
expect(controlDir.value).toBe(control.value);
489489
expect(controlDir.valid).toBe(control.valid);
@@ -648,8 +648,8 @@ class CustomValidatorDirective implements Validator {
648648
});
649649

650650
describe('FormControlName', () => {
651-
let formModel: any /** TODO #9100 */;
652-
let controlNameDir: any /** TODO #9100 */;
651+
let formModel: FormControl;
652+
let controlNameDir: FormControlName;
653653

654654
beforeEach(() => {
655655
formModel = new FormControl('name');

packages/forms/test/form_array_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ describe('FormArray', () => {
850850

851851
describe('valueChanges', () => {
852852
let a: FormArray;
853-
let c1: any /** TODO #9100 */, c2: any /** TODO #9100 */;
853+
let c1: FormControl, c2: FormControl;
854854

855855
beforeEach(() => {
856856
c1 = new FormControl('old1');

packages/forms/test/form_builder_spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import {FormBuilder, NonNullableFormBuilder, ReactiveFormsModule, UntypedFormBui
1111
import {of} from 'rxjs';
1212

1313
(function() {
14-
function syncValidator(_: any /** TODO #9100 */): any /** TODO #9100 */ {
14+
function syncValidator() {
1515
return null;
1616
}
17-
function asyncValidator(_: any /** TODO #9100 */) {
17+
function asyncValidator() {
1818
return Promise.resolve(null);
1919
}
2020

packages/forms/test/form_control_spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {fakeAsync, tick} from '@angular/core/testing';
10-
import {FormArray, FormControl, FormGroup, Validators} from '@angular/forms';
10+
import {AsyncValidatorFn, FormArray, FormControl, FormGroup, Validators} from '@angular/forms';
1111

1212
import {asyncValidator, asyncValidatorReturningObservable} from './util';
1313

@@ -16,7 +16,7 @@ function otherAsyncValidator() {
1616
return Promise.resolve({'other': true});
1717
}
1818

19-
function syncValidator(_: any /** TODO #9100 */): any /** TODO #9100 */ {
19+
function syncValidator() {
2020
return null;
2121
}
2222

@@ -1105,7 +1105,7 @@ describe('FormControl', () => {
11051105
it('should fire an event after the status has been updated to pending', fakeAsync(() => {
11061106
const c = new FormControl('old', Validators.required, asyncValidator('expected'));
11071107

1108-
const log: any[] /** TODO #9100 */ = [];
1108+
const log: string[] = [];
11091109
c.valueChanges.subscribe({next: (value: any) => log.push(`value: '${value}'`)});
11101110

11111111
c.statusChanges.subscribe({next: (status: any) => log.push(`status: '${status}'`)});
@@ -1133,7 +1133,7 @@ describe('FormControl', () => {
11331133

11341134
// TODO: remove the if statement after making observable delivery sync
11351135
it('should update set errors and status before emitting an event', done => {
1136-
c.valueChanges.subscribe((value: any /** TODO #9100 */) => {
1136+
c.valueChanges.subscribe(() => {
11371137
expect(c.valid).toEqual(false);
11381138
expect(c.errors).toEqual({'required': true});
11391139
done();
@@ -1507,7 +1507,8 @@ describe('FormControl', () => {
15071507
});
15081508

15091509
it('should throw when sync validator passed into async validator param', () => {
1510-
const fn = () => new FormControl('', syncValidator, syncValidator);
1510+
const fn = () =>
1511+
new FormControl('', syncValidator, syncValidator as unknown as AsyncValidatorFn);
15111512
// test for the specific error since without the error check it would still throw an error
15121513
// but
15131514
// not a meaningful one

0 commit comments

Comments
 (0)