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

ref element type not inferred correctly #5

Open
rafgraph opened this issue Apr 1, 2021 · 4 comments
Open

ref element type not inferred correctly #5

rafgraph opened this issue Apr 1, 2021 · 4 comments

Comments

@rafgraph
Copy link

rafgraph commented Apr 1, 2021

Hi, great library, thanks for creating it! I'm using it in React Interactive

Using the Heading forwardRef example in the readme the ref element type implicitly is any:
For a live reproduction see: https://codesandbox.io/s/polymorphic-inferred-ref-type-zqyl6

<Heading
  as="h1"
  color="green"
  // error: Parameter 'element' implicitly has an 'any' type.
  ref={(element) => {}}
>
  As h1
</Heading>

Note that when creating a props object to pass to Heading the ref element type is inferred correctly:

const propsForHeading: HeadingProps<"h1"> = {
  // element type is inferred correctly
  ref: (element) => {},
  children: "Heading using propsForHeading"
};

...

<Heading {...propsForHeading} />
@kripod
Copy link
Owner

kripod commented Apr 2, 2021

Hello,

Thank you again for reporting with a clear reproduction for your case.

Unfortunately, this seems to be a limitation of TypeScript rather than an issue with this library. Please follow along the following issue for further details: kripod/react-polymorphic-box#13

Please provide the element type explicitly until a fix is available:

<Heading
  as="h1"
  color="green"
  ref={(element: HTMLHeadingElement | null) => {}}
>
  As h1
</Heading>

@kripod kripod closed this as completed Apr 2, 2021
@rafgraph
Copy link
Author

rafgraph commented Apr 2, 2021

Thanks for the info. It looks like microsoft/TypeScript#31023 was merged in December, but not sure if it's been released yet.

@Mesoptier
Copy link

@kripod I think it's fair to assume that the previously mentioned PR has been released by now. Unfortunately this issue has not been fixed by that change. Perhaps you could re-open this issue?

@Mesoptier
Copy link

This comment is relevant for this issue as well:

This issue has now been fixed on TypeScript's end (microsoft/TypeScript#44596), so perhaps this issue can be fixed in a nicer way now?

#8 (comment)

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

3 participants