Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

TypeScript Definitions #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JonGinty
Copy link

Added single type definition file which contains definitions for both GridList and DraggableGridList.

There are a couple of lines in the definitions which I've commented out which allow the definitions to be used without depending on JQuery definitions as well. I can refactor into two separate definition files if that would be more suitable.

I've publicly exposed DraggableGridList as window member "window.DraggableGridList". I'm aware that's a controversial change so I could potentially refactor to avoid it. The issue is that using the "$(el).gridList()" constructor is incompatible with the widely used DefinitelyTyped definitions for JQuery.

… GridList and DraggableGridList.

Definition file depends on JQuery definitions but can be used without by replacing any line which references JQuery with the commented out line below it.
@catalinmiron
Copy link
Contributor

@JonGinty can't you do like this:

interface JQuery {
    gridList: GridlistPlugin<this>;
}
interface GridlistPlugin<TJQuery> {
    (methodName: string, ...args: any[]): TJQuery;
    (options?: GridlistOptions): TJQuery;
}
interface GridList {
    gridList: GridList;
    destroy(): void;
    resize(lanes: number): void;
    resizeItem(element: Element | string | JQuery, size: Dimension2): void;
    // resizeItem(element: Element | string | any, size: Dimension2): void;
    reflow(): void;
    render(): void;
}
interface GridListOptions {
    // ...
}

?

@JonGinty
Copy link
Author

Hey @catalinmiron,

Yeah that pretty much seems to do the trick. I did have to add a string indexer to the JQuery interface to get it to work in my code (compiler complained about missing JQuery methods and indexer).

interface JQuery {
    gridList: GridListPlugin<this>;
    [index: string]: any;
}

The downside to this seems to be that if (like me) you are using the type definitions for JQuery, you lose all of the JQuery strong typing. That said, I guess anyone could just comment out this new JQuery definition block if they have the definitions.

What do you reckon? Worth me amending the PR?

Cheers
Jon

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants