Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d3-selection: add generic func parameters to selection.call #64492

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions types/d3-selection/d3-selection-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,9 @@ function enforceMinRadius(selection: d3Selection.Selection<SVGCircleElement, Cir
});
}

// @ts-expect-error
circles.call(enforceMinRadius, '40'); // fails, minRadius of type number expected

// returns 'this' selection
circles = circles.call(enforceMinRadius, 40); // check chaining return type by re-assigning

Expand Down
3 changes: 2 additions & 1 deletion types/d3-selection/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Boris Yankov <https://github.com/borisyankov>
// denisname <https://github.com/denisname>
// Nathan Bierema <https://github.com/Methuselah96>
// Ambar Mutha <https://github.com/ambar-arkin>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you looking to become an owner of this package, get pinged on PRs, etc? If you're just looking for credit, we do that via the git history and this could be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am interested in becoming an owner and helping review PRs.

// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

// Last module patch version validated against: 3.0.0
Expand Down Expand Up @@ -878,7 +879,7 @@ export interface Selection<GElement extends BaseType, Datum, PElement extends Ba
* @param func A function which is passed this selection as the first argument along with any optional arguments.
* @param args List of optional arguments to be passed to the callback function.
*/
call(func: (selection: Selection<GElement, Datum, PElement, PDatum>, ...args: any[]) => void, ...args: any[]): this;
call<Args extends any[]>(func: (selection: Selection<GElement, Datum, PElement, PDatum>, ...args: Args) => void, ...args: Args): this;

/**
* Return true if this selection contains no (non-null) elements.
Expand Down