Skip to content

Commit

Permalink
fix: types for raw context menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
FedeIlLeone committed Oct 26, 2024
1 parent d3f9924 commit 88b5bd0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/types/coremods/contextMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ import type React from "react";

type ContextMenuComponents = Omit<ContextMenuType, "ItemColors" | "ContextMenu">;

interface BaseRawContextItem<T> {
type: T;
}
type RawContextMenuProps = {
[K in keyof ContextMenuComponents]: React.ComponentProps<ContextMenuComponents[K]> & {
type: ContextMenuComponents[K];
};
};

type WithRawChildren<T> = T extends { children: React.ReactNode }
? Omit<T, "children"> & { children: RawContextItem | RawContextItem[] }
: T;

// TODO: Type is not correctly extending the props of the component based on the generic T
export type RawContextItem<
T extends
ContextMenuComponents[keyof ContextMenuComponents] = ContextMenuComponents[keyof ContextMenuComponents],
> = BaseRawContextItem<T> & WithRawChildren<React.ComponentProps<T>>;
RawContextMenuProps[keyof RawContextMenuProps] = RawContextMenuProps[keyof RawContextMenuProps],
> = WithRawChildren<T>;

export type GetContextItem<T extends Record<string, unknown> = Record<string, unknown>> = (
data: T,
Expand Down

0 comments on commit 88b5bd0

Please sign in to comment.