0

I'm writing a TypeScript definition file for a jQuery library which has the following syntax:

$.library({ /* options object */ }); // Returns an Object
$.library.methodOne(); // Void
$.library.methodTwo(); // Void

So I tried writing the following interface:

interface JQueryStatic {
    library: StaticLibraryMethods; // Defines the static methods
    library(options:LibraryOptions): Object; // Defines the options overflow
}
interface StaticLibraryMethods {
    methodOne(): void;
    methodTwo(): void;
}

But I get an error in JQueryStatic:

Duplicate identifier "library"

Is there any way to write a definition for this kind of syntax without modifying library itself?

0

1 Answer 1

1

You have to define it like so:

interface JQueryStatic {
    (options: LibraryOptions): Object;
    library: StaticLibraryMethods; // Defines the static methods
}

interface StaticLibraryMethods {
    methodOne(): void;
    methodTwo(): void;
}

Or you could do this:

interface JQueryStatic {
    library: MyLibrary;
}

interface MyLibrary {
    (options: LibraryOptions): Object;
    methodOne(): void;
    methodTwo(): void;
}
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.