CCPony
CCPony

Reputation: 998

Missing methods in Breeze Typescript Definition File

In the latest Breeze Typescript definition file (https://github.com/borisyankov/DefinitelyTyped) there are missing methods, notably the Validator.register and the Validator.registerFactory methods. I'm wondering - - is this intentional, for some reason? Even though I can edit the definition files, I don't like to do it because my changes will disappear when a newer version is downloaded. Is there any way to extend a definition file?

Upvotes: 0

Views: 380

Answers (2)

Jay Traband
Jay Traband

Reputation: 17052

Edit: These are now available on Breeze v1.3.0


I will add these to the next version of Breeze, out later this next week.

As a side note, the most recent versions of the breeze typescript definition files can be found in the breeze zip file for each release in the 'TypeScript' dir. We try to keep the (https://github.com/borisyankov/DefinitelyTyped) updated as well, but there can be a delay, so its best to get it directly from the latest Breeze zip ( or directly from GitHub).

And thx for pointing this out, and if you see more please repost.

Upvotes: 3

basarat
basarat

Reputation: 276057

To answer: Is there any way to extend a definition file?

No. Validator is defined as a class. Class definitions are not open ended so the following is invalid:

declare class Validator  {
    static messageTemplates: any;
}

declare class Validator  {
    static register: any;
}

Validator was defined as a class since Interfaces do not support static methods. If typescript had supported static members on an interface then we could have done:

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

The you could have simply done:

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

and it would have worked since interfaces are open ended. Unfortunately in the definition file it is defined as a class i.e class Validator which is why there is no way of extending it other than modifying the definition file.

Upvotes: 1

Related Questions