nottinhill nottinhill - 1 month ago 24
TypeScript Question

Angular2: Return type of public static method from exported class has or is using private name

Error



Error at /Users/user/project/.tmp/shared/validation/validators/unicode-characters.validator.ts:12:52: Return type of public static method from exported class has or is using private name 'ValidationResult'.


Component



import {FormControl} from "@angular/forms";

interface ValidationResult {
[key:string]:boolean;
}

export class UnicodeCharactersValidator {

/* tslint:disable:max-line-length */
private static UNICODE_CHARS_PATTERN = /^[ \u0041-\u005A\u0061-\u007A\u00AA\u00B5\u00BA\u00C0]*$/;

public static check(formControl: FormControl): ValidationResult {
if ( !UnicodeCharactersValidator.UNICODE_CHARS_PATTERN.test(formControl.value) ) {
return { "invalidCharacters": true };
}
return null;
}

}


How can I fix this?

Answer

You have to export the interface as well:

export interface ValidationResult {
    [key:string]:boolean;
}

The public function returns a ValidationResult. Which means it is accessible from the outside. That's why you should also export the ValidationResult :)

Comments