Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/lodash-declaration-types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"victory-brush-container": patch
"victory-cursor-container": patch
"victory-selection-container": patch
"victory-shared-events": patch
"victory-voronoi-container": patch
"victory-zoom-container": patch
---

Type declarations no longer reference lodash's types, which consumers don't have (`@types/lodash` isn't a dependency): they resolved to `any`, or failed with TS7016 under `skipLibCheck: false`. The throttled helper handlers (`BrushHelpers.onGlobalMouseMove`, `onMouseMove`, `ZoomHelpers.onWheel`, ...) are now typed with their call signature, `cancel()` and `flush()`, and `VictorySharedEvents`'s `getBaseProps`/`getBasePropsFromChildren` return `Record<string, any>`.
16 changes: 14 additions & 2 deletions packages/victory-brush-container/src/brush-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import throttle from "lodash/throttle";
import { Helpers as CoreHelpers, Selection } from "victory-core";
import isEqual from "react-fast-compare";

// lodash's `DebouncedFuncLeading`, spelled out so the published declarations
// don't reference `@types/lodash`, which consumers don't have.
type Throttled<T extends (...args: any[]) => any> = {
(...args: Parameters<T>): ReturnType<T>;
cancel(): void;
flush(): ReturnType<T>;
};

const throttleLeading = <T extends (...args: any[]) => any>(
fn: T,
wait: number,
): Throttled<T> => throttle(fn, wait, { leading: true, trailing: false });

const Helpers = {
getDimension(props) {
const { horizontal, brushDimension } = props;
Expand Down Expand Up @@ -494,9 +507,8 @@ export const BrushHelpers = {
...Helpers,
onMouseDown: Helpers.onMouseDown.bind(Helpers),
onGlobalMouseUp: Helpers.onGlobalMouseUp.bind(Helpers),
onGlobalMouseMove: throttle(
onGlobalMouseMove: throttleLeading(
Helpers.onGlobalMouseMove.bind(Helpers),
16, // eslint-disable-line no-magic-numbers
{ leading: true, trailing: false },
),
};
21 changes: 17 additions & 4 deletions packages/victory-cursor-container/src/cursor-helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ import throttle from "lodash/throttle";

const ON_MOUSE_MOVE_THROTTLE_MS = 16;

// lodash's `DebouncedFuncLeading`, spelled out so the published declarations
// don't reference `@types/lodash`, which consumers don't have.
type Throttled<T extends (...args: any[]) => any> = {
(...args: Parameters<T>): ReturnType<T>;
cancel(): void;
flush(): ReturnType<T>;
};

const throttleLeading = <T extends (...args: any[]) => any>(
fn: T,
wait: number,
): Throttled<T> => throttle(fn, wait, { leading: true, trailing: false });

class CursorHelpersClass {
getDimension(props) {
const { horizontal, cursorDimension } = props;
Expand Down Expand Up @@ -66,10 +79,10 @@ class CursorHelpersClass {
];
};

onMouseMove = throttle(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
leading: true,
trailing: false,
});
onMouseMove = throttleLeading(
this.handleMouseMove,
ON_MOUSE_MOVE_THROTTLE_MS,
);

onMouseLeave = this.handleMouseMove;

Expand Down
21 changes: 17 additions & 4 deletions packages/victory-selection-container/src/selection-helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ import React from "react";

const ON_MOUSE_MOVE_THROTTLE_MS = 16;

// lodash's `DebouncedFuncLeading`, spelled out so the published declarations
// don't reference `@types/lodash`, which consumers don't have.
type Throttled<T extends (...args: any[]) => any> = {
(...args: Parameters<T>): ReturnType<T>;
cancel(): void;
flush(): ReturnType<T>;
};

const throttleLeading = <T extends (...args: any[]) => any>(
fn: T,
wait: number,
): Throttled<T> => throttle(fn, wait, { leading: true, trailing: false });

class SelectionHelpersClass {
getDimension(props) {
const { horizontal, selectionDimension } = props;
Expand Down Expand Up @@ -155,10 +168,10 @@ class SelectionHelpersClass {
};
};

onMouseMove = throttle(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
leading: true,
trailing: false,
});
onMouseMove = throttleLeading(
this.handleMouseMove,
ON_MOUSE_MOVE_THROTTLE_MS,
);

onMouseUp = (evt, targetProps) => {
const { activateSelectedData, allowSelection, x2, y2 } = targetProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class VictorySharedEvents extends React.Component<VictorySharedEventsProp
return Object.assign({}, childBaseProps, { parent: parentBaseProps });
}

getBasePropsFromChildren(childComponents) {
getBasePropsFromChildren(childComponents): Record<string, any> {
const iteratee = (child, childName) => {
if (child.type && Helpers.isFunction(child.type.getBaseProps)) {
const baseProps = child.props && child.type.getBaseProps(child.props);
Expand Down
21 changes: 17 additions & 4 deletions packages/victory-voronoi-container/src/voronoi-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ const Delaunay = (DelaunayModule as any).default ?? DelaunayModule;

const ON_MOUSE_MOVE_THROTTLE_MS = 32;

// lodash's `DebouncedFuncLeading`, spelled out so the published declarations
// don't reference `@types/lodash`, which consumers don't have.
type Throttled<T extends (...args: any[]) => any> = {
(...args: Parameters<T>): ReturnType<T>;
cancel(): void;
flush(): ReturnType<T>;
};

const throttleLeading = <T extends (...args: any[]) => any>(
fn: T,
wait: number,
): Throttled<T> => throttle(fn, wait, { leading: true, trailing: false });

class VoronoiHelpersClass {
withinBounds(props, point) {
const { width, height, polar, origin, scale } = props;
Expand Down Expand Up @@ -260,10 +273,10 @@ class VoronoiHelpersClass {
return parentMutations.concat(...inactiveMutations, ...activeMutations);
};

onMouseMove = throttle(this.handleMouseMove, ON_MOUSE_MOVE_THROTTLE_MS, {
leading: true,
trailing: false,
});
onMouseMove = throttleLeading(
this.handleMouseMove,
ON_MOUSE_MOVE_THROTTLE_MS,
);
}

export const VoronoiHelpers = new VoronoiHelpersClass();
19 changes: 15 additions & 4 deletions packages/victory-zoom-container/src/zoom-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ import throttle from "lodash/throttle";

import { Helpers, Selection, Collection, Wrapper } from "victory-core";

// lodash's `DebouncedFuncLeading`, spelled out so the published declarations
// don't reference `@types/lodash`, which consumers don't have.
type Throttled<T extends (...args: any[]) => any> = {
(...args: Parameters<T>): ReturnType<T>;
cancel(): void;
flush(): ReturnType<T>;
};

const throttleLeading = <T extends (...args: any[]) => any>(
fn: T,
wait: number,
): Throttled<T> => throttle(fn, wait, { leading: true, trailing: false });

export const RawZoomHelpers = {
checkDomainEquality(a, b) {
const checkDimension = (dim) => {
Expand Down Expand Up @@ -368,14 +381,12 @@ export const ZoomHelpers = {
onMouseDown: RawZoomHelpers.onMouseDown.bind(RawZoomHelpers),
onMouseUp: RawZoomHelpers.onMouseUp.bind(RawZoomHelpers),
onMouseLeave: RawZoomHelpers.onMouseLeave.bind(RawZoomHelpers),
onMouseMove: throttle(
onMouseMove: throttleLeading(
RawZoomHelpers.onMouseMove.bind(RawZoomHelpers),
16, // eslint-disable-line no-magic-numbers
{ leading: true, trailing: false },
),
onWheel: throttle(
onWheel: throttleLeading(
RawZoomHelpers.onWheel.bind(RawZoomHelpers),
16, // eslint-disable-line no-magic-numbers
{ leading: true, trailing: false },
),
};
14 changes: 0 additions & 14 deletions scripts/pack-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,7 @@ const ALLOWED_CJS_DEFAULT_IMPORTS = {
// same with `@types/react` 18 and 19. Fixing them changes published types
// (tracked in #3093). Anything else fails, and so does a count that no longer
// matches.
//
// TS7016: these declarations use lodash types (inferred from lodash calls),
// but `@types/lodash` isn't a dependency, so consumers get `any`. Fixed with
// explicit types in the source; lodash itself is to be removed (#2711).
const lodashTypes = (file, count) => ({
[`dist/${file}.d.cts:TS7016`]: count,
[`dist/${file}.d.mts:TS7016`]: count,
});
const ALLOWED_DECLARATION_ERRORS = {
"victory-brush-container": lodashTypes("brush-helpers", 1),
"victory-cursor-container": lodashTypes("cursor-helpers", 1),
"victory-selection-container": lodashTypes("selection-helpers", 1),
"victory-shared-events": lodashTypes("victory-shared-events", 2),
"victory-voronoi-container": lodashTypes("voronoi-helpers", 1),
"victory-zoom-container": lodashTypes("zoom-helpers", 2),
"victory-create-container": {
// `createContainer`'s inferred return type indexes the container map with
// a type parameter that isn't narrowed to `ContainerType`.
Expand Down
Loading