reachtokish / rctx-contextmenu

:bowtie: :sparkles: Context menu for React
https://reachtokish.github.io/rctx-contextmenu/
67 stars 15 forks source link

Type Issue for children props in index.d.ts #34

Closed Crypto-zombie closed 1 year ago

Crypto-zombie commented 1 year ago

Relevant code or config

Right Click On Me
Menu Item 1 Menu Item 2 Menu Item 3 Menu Item 4

What you did:

I just tried to run sample code on react-typescript project.

"react": "^18.2.0", "typescript": "^4.7.4",

What happened:

Type '{ children: Element[]; id: string; appendTo: string; animation: string; }' is not assignable to type 'IntrinsicAttributes & ContextMenu'. Property 'children' does not exist on type 'IntrinsicAttributes & ContextMenu'. 3 | const CustomContextMenu = () => { 4 | return (

5 | <ContextMenu | ^^^^^^^^^^^

Problem description:

Type '{ children: Element[]; id: string; appendTo: string; animation: string; }' is not assignable to type 'IntrinsicAttributes & ContextMenu'.

Suggested solution: I solved this problem like this:

rctx-contextmenu/src/index.d.ts

export interface ContextMenu { id: string, appendTo?: string, animation?: string, hideOnLeave?: boolean, attributes?: object, className?: string, preventHideOnResize?: boolean, preventHideOnScroll?: boolean, onShow?: {(event: any): void}, onHide?: {(event: any): void}, children?: ReactNode, ---------------------------------------> onMouseLeave?: {(event: any): void} }

export interface ContextMenuItem { disabled?: boolean, preventClose?: boolean, disableWhileShiftPressed?: boolean, attributes?: object, className?: string, children?: ReactNode, ----------------------------------------> onClick?: {(event: any): void} }

export interface ContextMenuTrigger { id: string, attributes?: object, disable?: boolean, className?: string, children?: ReactNode -------------------------------------------> }

export interface Submenu { title: string, attributes?: object, className?: boolean, children?: ReactNode --------------------------------------------> }

I would like you to solve this issues as soon as possible. Best Regards

Evgenii

CodingDive commented 1 year ago

I'd also love to see a fix for this. For the time being, you can use module augmentation to add the missing types

// types.d.tsx
declare module 'rctx-contextmenu' {
  interface ContextMenu {
    children?: ReactNode;
  }

  interface ContextMenuItem {
    children?: ReactNode;
  }

  interface ContextMenuTrigger {
    children?: ReactNode;
  }

  interface Submenu {
    children?: ReactNode;
  }
}
reachtokish commented 1 year ago

Thanks for raising the issue.

This is resolved. Kindly use the latest version (1.4.1). Closing the ticket. Kindly open if it still exist