desandro / masonry

:love_hotel: Cascading grid layout plugin
https://masonry.desandro.com
16.44k stars 2.11k forks source link

Some type errors persist after loading masonry types #1167

Open haydentech opened 2 years ago

haydentech commented 2 years ago

I'm attempting to convert a working JavaScript project using Masonry, ImagesLoaded, and InfiniteScroll over to TypeScript. The types for Masonry are available using "npm install --save @types/masonry-layout". After loading the types, many errors went away, but I'm still getting type errors for several places that appear to be working, correct code taken right from your sample code. Here are some examples:

$grid.masonry("destroy"); // https://masonry.desandro.com/methods.html#destroy

 Type '"destroy"' has no properties in common with type 'Options'.ts(2559)

$grid.masonry( 'remove', this ); // https://masonry.desandro.com/methods.html#remove

Expected 0-1 arguments, but got 2.ts(2554)

Basically any construct with .masonry(string) is not accepted. Is there a shortcoming in the types files, or am I doing something wrong?

haydentech commented 2 years ago

Adding the specified line to index.d.ts seems to fix all the issues:

declare global {
    interface JQuery {
        masonry(options?: Masonry.Options): JQuery;
    masonry(selector: string | Element, options?: Masonry.Options | JQuery): JQuery;   // add this line
    }
}