tune2fs
tune2fs

Reputation: 7705

Typescript definitions file cannot make a method implement an object interface

I want to generate a definition file for pnotify.

/// <reference path="./jquery.d.ts"/>

interface pnotifyDefaults {
    styling?: string;
    history?: boolean;
}

interface pnotifyInterface {
    defaults?: pnotifyDefaults
}

interface JQueryStatic {
    pnotify(options: any): any;

    pnotify: pnotifyInterface;

    pnotify_remove_all(): void;

}


declare module 'jquery.pnotify' {
}

This accutally does not compile and the compiler complains:

Duplicate identifier 'pnotify'. Additional locations: jquery.pnotify.d.ts(15,5)

But how can I achieve that behaviour as in my js code I want to use pnotify like:

$.pnotify(opts)

But also like that:

$.pnotify.defaults.history = false;

Upvotes: 1

Views: 137

Answers (1)

thomaux
thomaux

Reputation: 19738

You need to specify a call signature on pnotifyInterface, update your definitions to:

interface pnotifyDefaults {
    styling?: string;
    history?: boolean;
}

interface pnotifyInterface {
    defaults?: pnotifyDefaults
    (options: any): any;
}

interface JQueryStatic {
    pnotify: pnotifyInterface;

    pnotify_remove_all(): void;

}


declare module 'jquery.pnotify' {
}

You were receiving the error because you were declaring pnotify twice on the JQueryStatic interface.

Upvotes: 1

Related Questions