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

Victory native type fixes #2785

Merged
merged 4 commits into from Feb 6, 2024
Merged

Victory native type fixes #2785

merged 4 commits into from Feb 6, 2024

Conversation

KenanYusuf
Copy link
Member

@KenanYusuf KenanYusuf commented Feb 6, 2024

Problem

Relates to #2784

There were a couple of issues with the types in the victory-native package, caused by #2739.

Wrapped components

Components that were wrapped with the wrapCoreComponent HOC were only accepting props that were passed to the defaultProps object. For example:

export const VictoryLine = wrapCoreComponent({
  Component: VictoryLineBase,
  defaultProps: {
    width: Dimensions.get("window").width,
  },
});

const Example = () => (
  <VictoryLine
    width={400} // ✅ exists in defaultProps
    data={[]} // ❌ does not exist in defaultProps
  />
);

I have updated this by ensuring that the base component's props are passed as a generic to the wrapCoreComponent function:

export const VictoryLine = wrapCoreComponent<VictoryLineProps>({
  Component: VictoryLineBase,
  defaultProps: {
    width: Dimensions.get("window").width,
  },
});

const Example = () => (
  <VictoryLine
    width={400} // ✅ exists in VictoryLineProps
    data={[]} // ✅ exists in VictoryLineProps
  />
);

Container components

The victory-*-container component props were being typed incorrectly as the type of the original component props. For example:

const combinedMixin = flow(originalVoronoiMixin, nativeVoronoiMixin);

export const voronoiContainerMixin = (base): VictoryVoronoiContainerBase =>
  combinedMixin(base);

export const VictoryVoronoiContainer = voronoiContainerMixin(VictoryContainer)

In the above example, VictoryVoronoiContainerBase is the typeof the base victory component. To fix this, the types were updated so that the return type of combinedMixin is a class component with the props for the victory-native version:

const combinedMixin: (
  base: React.ComponentClass,
) => React.ComponentClass<VictoryVoronoiContainerNativeProps> = flow(
  originalVoronoiMixin,
  nativeVoronoiMixin,
);

export const voronoiContainerMixin = (base: React.ComponentClass) =>
  combinedMixin(base);

export const VictoryVoronoiContainer = voronoiContainerMixin(VictoryContainer);

Copy link

changeset-bot bot commented Feb 6, 2024

🦋 Changeset detected

Latest commit: e693496

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
victory-brush-container Patch
victory-cursor-container Patch
victory-line Patch
victory-native Patch
victory-selection-container Patch
victory-voronoi-container Patch
victory-zoom-container Patch
victory-area Patch
victory-axis Patch
victory-bar Patch
victory-box-plot Patch
victory-brush-line Patch
victory-candlestick Patch
victory-canvas Patch
victory-chart Patch
victory-core Patch
victory-create-container Patch
victory-errorbar Patch
victory-group Patch
victory-histogram Patch
victory-legend Patch
victory-pie Patch
victory-polar-axis Patch
victory-scatter Patch
victory-shared-events Patch
victory-stack Patch
victory-tooltip Patch
victory-vendor Patch
victory-voronoi Patch
victory Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Feb 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
victory ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 6, 2024 11:08am

@@ -120,4 +120,3 @@ export function selectionContainerMixin<

export const VictorySelectionContainer =
selectionContainerMixin(VictoryContainer);
export type VictorySelectionContainer = typeof VictorySelectionContainer;
Copy link
Member Author

@KenanYusuf KenanYusuf Feb 6, 2024

Choose a reason for hiding this comment

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

These types are no longer necessary for typing the victory-native container components

@carbonrobot
Copy link
Contributor

Published 36.9.1-next.0 for testing

@KenanYusuf KenanYusuf merged commit 0270049 into main Feb 6, 2024
10 checks passed
@KenanYusuf KenanYusuf deleted the victory-native-type-fixes branch February 6, 2024 15:06
@victory-ci victory-ci mentioned this pull request Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants