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 type errors rendering ComponentType #2398

Closed
nickofthyme opened this issue Apr 9, 2024 · 0 comments · Fixed by #2440
Closed

React type errors rendering ComponentType #2398

nickofthyme opened this issue Apr 9, 2024 · 0 comments · Fixed by #2440
Labels
bug Something isn't working dependencies Pull requests that update a dependency file

Comments

@nickofthyme
Copy link
Collaborator

nickofthyme commented Apr 9, 2024

In a few places throughout charts we render custom components on the type ComponentType<Props>. Like the LegendColorPicker to define a custom color picker.

/** @public */
export type LegendColorPicker = ComponentType<LegendColorPickerProps>;

Lately I've started seeing error where typescript is complaining about these components with the following error...

image
'ColorPicker' cannot be used as a JSX component.
  Its element type 'ReactElement<any, any> | Component<LegendColorPickerProps, any, any> | null' is not a valid JSX element.
    Type 'Component<LegendColorPickerProps, any, any>' is not assignable to type 'Element | ElementClass | null'.
      Type 'Component<LegendColorPickerProps, any, any>' is not assignable to type 'ElementClass'.
        The types returned by 'render()' are incompatible between these types.
          Type 'React.ReactNode' is not assignable to type 'import("/Users/nickpartridge/Documents/repos/elastic-charts/docs/node_modules/@types/react/index").ReactNode'.ts(2786)

If I were to use the renderWithProps utility like below, the error goes away.

return renderWithProps(ColorPicker, {
  anchor: this.colorRef.current,
  color,
  onClose: handleClose,
  onChange: handleChange,
  seriesIdentifiers,
});

I'm not sure if this is a typing issue or what but the functionality is unaffected. But we should look into this to resolve the type errors.

These errors do not appear as type errors in main but do appear when you add the exact @types/react to the top-level package.json. I think they always show in the IDE.

See example build errors at https://buildkite.com/elastic/datavis-ci/builds/3508#018ec3c1-2ccd-405a-834b-3a7ce5879bbb

@nickofthyme nickofthyme added the bug Something isn't working label Apr 9, 2024
@nickofthyme nickofthyme changed the title React Component type errors React type errors rendering ComponentType Apr 9, 2024
@markov00 markov00 added the dependencies Pull requests that update a dependency file label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants