Angular2:来自导出类的公共静态方法的返回类型具有或正在使用私有名称

时间:2016-10-10 14:08:58

标签: angular typescript

错误

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'.

组件

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;
    }

}

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:4)

您还必须导出界面:

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

公共函数返回ValidationResult。这意味着它可以从外部访问。这就是为什么你也应该导出ValidationResult:)