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

ContextMenuProps in version 5.x.x has typing conflict with @types/react v18.2.14 #6270

Closed
pettyron opened this issue Jul 10, 2023 · 2 comments · Fixed by #6274
Closed

ContextMenuProps in version 5.x.x has typing conflict with @types/react v18.2.14 #6270

pettyron opened this issue Jul 10, 2023 · 2 comments · Fixed by #6274

Comments

@pettyron
Copy link

pettyron commented Jul 10, 2023

Environment

React 18 (@types/react v18.2.14), TypeScript 5, Windows 10, Node v16

  • Package version(s): @blueprintjs/core@5.0.1
  • Operating System: Windows 10
  • Browser name and version: Chrome 114.0.5735.199

Steps to reproduce

  1. Running tsc command to build output triggers the error.

Actual behavior

Console returns this error:

node_modules/@blueprintjs/core/lib/esm/components/context-menu/contextMenu.d.ts:33:18 - error TS2430: Interface 'ContextMenuProps' incorrectly extends interface 'Omit<HTMLAttributes<HTMLElement>, "className" | "children" | "onContextMenu">'.
  Types of property 'content' are incompatible.
    Type 'Element | ((props: ContextMenuContentProps) => Element)' is not assignable to type 'string'.
      Type 'Element' is not assignable to type 'string'.

Expected behavior

No error

Possible solution

// The solution is that the interface should look like this:
export interface ContextMenuProps extends Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | "content" | "onContextMenu">, React.RefAttributes<any>, Props {
    /**
     * Menu content. This will usually be a Blueprint `<Menu>` component.
     * This optionally functions as a render prop so you can use component state to render content.
     */
    content: JSX.Element | ((props: ContextMenuContentProps) => JSX.Element | undefined) | undefined;
    ...
}

// But instead it looks like this:
export interface ContextMenuProps extends Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | "onContextMenu">, React.RefAttributes<any>, Props {
    /**
     * Menu content. This will usually be a Blueprint `<Menu>` component.
     * This optionally functions as a render prop so you can use component state to render content.
     */
    content: JSX.Element | ((props: ContextMenuContentProps) => JSX.Element | undefined) | undefined;
    ...
}
@pettyron
Copy link
Author

pettyron commented Jul 10, 2023

The reason this fails, as it does, is because the latest React types has in their HTMLAttributes interface, listed under RDFa Attributes, content?: string | undefined.

@pettyron
Copy link
Author

pettyron commented Jul 10, 2023

I was able to roll my types for React back to @types/react v18.0.28 along with setting yarn resolutions, in my packages.json, to use this React types version. That resolves my issue and it helps to inform you this is only a conflict with React's latest typings (v18.2.14).

@pettyron pettyron changed the title ContextMenuProps has incorrect typing in version 5.x.x ContextMenuProps in version 5.x.x has typing conflict with @types/react v18.2.14 Jul 10, 2023
@adidahiya adidahiya self-assigned this Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants