Angular 2- Error: Type 'AbstractControl' is not assignable to type 'AbstractControl'

A J Qarshi

I am using the angular rc4 release to write an application where I have to impose few validation rules to form components like required, minlength along with some custom validator emailValidator.

When I pass one built in and one custom validator to the Validators.compose function, IDEs (both Webstorm & VS Code) display me compile time error messages like the one shown below:

enter image description here

However, you can see that in the above screenshot if both validators are built in, there is no error message.

The definition of my custom validator is given below:

static emailValidator(control: AbstractControl): {[key: string]: boolean} {
    if (control.value.match(/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/)) {
      return null;
    } else {
      return {'invalidEmailAddress': true };
    }
}
A J Qarshi

I solved the problem by replacing the type of control parameter from AbstractControl to Control as shown below:

static emailValidator(control: Control): {[key: string]: boolean} {
    if (control.value.match(/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/)) {
      return null;
    } else {
      return {'invalidEmailAddress': true };
    }
}

Control class extends from AbstractControl. I still don't understand why I get this error message when I use FormControl or AbstractControl.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Angular 2- Error: Type 'AbstractControl' is not assignable to type 'AbstractControl'

From Dev

Angular2: Error - Property 'updateValue' does not exist on type 'AbstractControl'

From Java

Property 'controls' does not exist on type 'AbstractControl' Angular 4

From Dev

Angular2 Error: Type 'number' is not assignable to type 'NumberConstructor'

From Dev

Angular2 : Type 'Subscription' is not assignable to type

From Dev

Type \'Observable<{}>\' is not assignable to type in angular 2

From Dev

Angular2 Error 'Argument of type '{}' is not assignable...'

From Dev

Angular 2 bootstrap function gives error "Argument type AppComponent is not assignable to parameter type Type"

From Dev

IntelliJ and Angular 2 Argument Type Not Assignable Errors

From Dev

Angular 2 and typescript argument of type response is not assignable

From Dev

Angular2 and TypeScript: error TS2322: Type 'Response' is not assignable to type 'UserStatus'

From Dev

error TS2322: Type 'Object' is not assignable to type 'Contact'. Angular

From Dev

angular2 Type 'Subject<{}>' is not assignable to type '() => Subject<number>'

From Dev

angular2 Type 'Subject<{}>' is not assignable to type '() => Subject<number>'

From Dev

Argument of type 'number' is not assignable to parameter of type 'string' in angular2.

From Dev

Angular: error TS2322: Type 'Observable<{}>' is not assignable ... with share() operator

From Dev

Invokespecial Verify Error: Type is not assignable

From Dev

TypeScript error: Type 'void' is not assignable to type 'boolean'

From Java

Error: Type 'void' is not assignable to type 'HttpEvent<any>'

From Dev

Error: Type 'string' is not assignable to type 'number' with toFixed()

From Dev

Typescript: Type 'null' is not assignable to type error

From Dev

ionic 2 "Type '{}' is not assignable to type 'any[]"

From Dev

Angular 5 error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'

From Dev

Angular2 authentication - Type 'AsyncSubject<{}>' is not assignable to type 'AsyncSubject<boolean> - observables and typescript

From Dev

Angular 2 RC-4 forms, Type 'FormGroup' is not assignable to type 'typeof FormGroup'

From Dev

Angular 2 RC-4 forms, Type 'FormGroup' is not assignable to type 'typeof FormGroup'

From Dev

Angular2 - Argument of type 'QueryList<ElementRef>' is not assignable to parameter of type 'string'

From Java

Angular - Response is not assignable to type 'request?: HttpRequest<any>

From Dev

Type '{}' is not assignable to type 'string'

Related Related

  1. 1

    Angular 2- Error: Type 'AbstractControl' is not assignable to type 'AbstractControl'

  2. 2

    Angular2: Error - Property 'updateValue' does not exist on type 'AbstractControl'

  3. 3

    Property 'controls' does not exist on type 'AbstractControl' Angular 4

  4. 4

    Angular2 Error: Type 'number' is not assignable to type 'NumberConstructor'

  5. 5

    Angular2 : Type 'Subscription' is not assignable to type

  6. 6

    Type \'Observable<{}>\' is not assignable to type in angular 2

  7. 7

    Angular2 Error 'Argument of type '{}' is not assignable...'

  8. 8

    Angular 2 bootstrap function gives error "Argument type AppComponent is not assignable to parameter type Type"

  9. 9

    IntelliJ and Angular 2 Argument Type Not Assignable Errors

  10. 10

    Angular 2 and typescript argument of type response is not assignable

  11. 11

    Angular2 and TypeScript: error TS2322: Type 'Response' is not assignable to type 'UserStatus'

  12. 12

    error TS2322: Type 'Object' is not assignable to type 'Contact'. Angular

  13. 13

    angular2 Type 'Subject<{}>' is not assignable to type '() => Subject<number>'

  14. 14

    angular2 Type 'Subject<{}>' is not assignable to type '() => Subject<number>'

  15. 15

    Argument of type 'number' is not assignable to parameter of type 'string' in angular2.

  16. 16

    Angular: error TS2322: Type 'Observable<{}>' is not assignable ... with share() operator

  17. 17

    Invokespecial Verify Error: Type is not assignable

  18. 18

    TypeScript error: Type 'void' is not assignable to type 'boolean'

  19. 19

    Error: Type 'void' is not assignable to type 'HttpEvent<any>'

  20. 20

    Error: Type 'string' is not assignable to type 'number' with toFixed()

  21. 21

    Typescript: Type 'null' is not assignable to type error

  22. 22

    ionic 2 "Type '{}' is not assignable to type 'any[]"

  23. 23

    Angular 5 error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'

  24. 24

    Angular2 authentication - Type 'AsyncSubject<{}>' is not assignable to type 'AsyncSubject<boolean> - observables and typescript

  25. 25

    Angular 2 RC-4 forms, Type 'FormGroup' is not assignable to type 'typeof FormGroup'

  26. 26

    Angular 2 RC-4 forms, Type 'FormGroup' is not assignable to type 'typeof FormGroup'

  27. 27

    Angular2 - Argument of type 'QueryList<ElementRef>' is not assignable to parameter of type 'string'

  28. 28

    Angular - Response is not assignable to type 'request?: HttpRequest<any>

  29. 29

    Type '{}' is not assignable to type 'string'

HotTag

Archive