1

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;

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.