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

React.JSX.Element type in select ItemRenderer type is not compatible with@types/react < 18.2.6 #6841

Open
MatthewHerbst opened this issue Jun 1, 2024 · 2 comments
Assignees

Comments

@MatthewHerbst
Copy link

MatthewHerbst commented Jun 1, 2024

Environment

  • Package version(s):
          "@blueprintjs/core": "^5.10.3",
          "@blueprintjs/datetime": "^5.3.4",
          "@blueprintjs/datetime2": "^2.3.4",
          "@blueprintjs/icons": "^5.9.0",
          "@blueprintjs/select": "^5.1.5",
          "@blueprintjs/table": "^5.1.5",
          "@blueprintjs/timezone": "^4.5.43",
          "react": "^17.0.2",
          ...
          "@types/react": "17.0.53",
  • Operating System: MacOS Sonoma 14.5
  • Browser name and version: Chrome 125.0.6422.112
  • react version: 17.0.2
  • @types/react version: 17.0.53

Code Sandbox

Link to a minimal repro (fork this code sandbox):

Steps to reproduce

  1. Install the packages listed
  2. Run your types build

Actual behavior

Trying to build types failed:

node_modules/@blueprintjs/select/src/common/itemRenderer.ts:72:80 - error TS2694: Namespace 'React' has no exported member 'JSX'.

72 export type ItemRenderer<T> = (item: T, itemProps: ItemRendererProps) => React.JSX.Element | null;
                                                                                  ~~~


Found 1 error in node_modules/@blueprintjs/select/src/common/itemRenderer.ts:72

Expected behavior

There are no type errors

Possible solution

React.JSX.Element was introduced in@types/react@18.2.6. This makes its use incompatible with the @blueprintjs/select@5.1.5 package's peerDependencies which specifies:

  "peerDependencies": {
    "@types/react": "^16.14.41 || 17 || 18",
    "react": "^16.8 || 17 || 18",
    "react-dom": "^16.8 || 17 || 18"
  },

Older versions of React could be supported by changing from React.JSX.Element -> JSX.Element, though I have only tested with @types/react@17.0.53. I have not tested with @types/react@16.14.41.

@gluxon
Copy link
Contributor

gluxon commented Jun 5, 2024

Thanks for reporting a bug!

React.JSX.Element was introduced in@types/react@18.2.6.

It looks like that change also edited @types/react versions v15, v16, and v17. 🤔

Adi updated the minimum Blueprint supported version to v16.14.41 here: #6634

@types/react is now on the latest v16 typings. There was a change to deprecate the global JSX namespace in favor of the React.JSX namespace in May 2023 via DefinitelyTyped/DefinitelyTyped@f1b2559, which was released in v16.14.41, so that is now the new minimum supported version of React types.

I think the right fix here is to be more specific Blueprint's @types/react peer dependencies and include minimum versions for 17.x and 18.x as well. Example:

{
  "peerDependencies": {
    "@types/react": "^16.14.41 || ^17.0.59 || ^18.2.6"
  }
}

I'm hesitant to go back to the unnamespaced JSX.Element since that's deprecated, even on older versions of @types/react.

@MatthewHerbst Does the above make sense? Could you upgrade your project to @types/react@17.0.59 or greater?

@gluxon gluxon self-assigned this Jun 5, 2024
@MatthewHerbst
Copy link
Author

MatthewHerbst commented Jun 6, 2024

Thanks for the response, @types/react@17.0.59 works!

My main reasoning for suggesting returning to JSX.Element was to avoid any potential semver major version change issue (not sure if that's required for the peer dep change being asked for, but I think technically it is?). Will let y'all decide on that though, a patch version with clear docs about why folks might be getting new peer dep warnings is probably fine since they don't need to make a major version change to @types/react. Thanks!

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

No branches or pull requests

2 participants