Stephan K.
Stephan K.

Reputation: 15732

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?

Upvotes: 1

Views: 1278

Answers (1)

Poul Kruijt
Poul Kruijt

Reputation: 71961

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 :)

Upvotes: 5

Related Questions