0

在最新的 Breeze Typescript 定义文件 ( https://github.com/borisyankov/DefinitelyTyped ) 中缺少方法,特别是 Validator.register 和 Validator.registerFactory 方法。我想知道——出于某种原因,这是故意的吗?尽管我可以编辑定义文件,但我不喜欢这样做,因为下载更新版本时我的更改会消失。有没有办法扩展定义文件?

4

2 回答 2

3

编辑:这些现在在 Breeze v1.3.0 上可用


我会将这些添加到下周晚些时候发布的 Breeze 的下一个版本中。

附带说明一下,可以在“TypeScript”目录中每个版本的微风 zip 文件中找到最新版本的微风打字稿定义文件。我们也尝试保持 ( https://github.com/borisyankov/DefinitelyTyped ) 的更新,但可能会有延迟,因此最好直接从最新的 Breeze zip(或直接从 GitHub)获取。

并感谢您指出这一点,如果您看到更多请转发。

于 2013-04-14T07:25:02.933 回答
1

回答:有没有办法扩展定义文件?

不,Validator 被定义为一个类。类定义不是开放式的,因此以下内容无效:

declare class Validator  {
    static messageTemplates: any;
}

declare class Validator  {
    static register: any;
}

Validator 被定义为一个类,因为接口不支持静态方法。如果 typescript 在接口上支持静态成员,那么我们可以这样做:

interface Validator {
    static messageTemplates: any;

    constructor (name: string, validatorFn: ValidatorFunction, context?: any);

    static bool(): Validator;
    static byte(): Validator;
    static date(): Validator;
    static duration(): Validator;
    getMessage(): string;
    static guid(): Validator;
    static int16(): Validator;
    static int32(): Validator;
    static int64(): Validator;
    static maxLength(context: { maxLength: number; }): Validator;
    static number(): Validator;
    static required(): Validator;
    static string(): Validator;
    static stringLength(context: { maxLength: number; minLength: number; }): Validator;
    validate(value: any, context?: any): ValidationError;
}

你可以简单地完成:

interface Validator {
    register(); // Whatever your signature was 
 }

由于接口是开放式的,因此它会起作用。不幸的是,在定义文件中它被定义为一个类class Validator,这就是为什么除了修改定义文件之外没有办法扩展它的原因。

于 2013-04-15T02:23:35.613 回答