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

Module "preact/compat" has no exported member ElementRef #4481

Open
1 task done
PratikDev opened this issue Aug 27, 2024 · 13 comments · May be fixed by #4557
Open
1 task done

Module "preact/compat" has no exported member ElementRef #4481

PratikDev opened this issue Aug 27, 2024 · 13 comments · May be fixed by #4557
Labels

Comments

@PratikDev
Copy link

  • Check if updating to the latest Preact version resolves the issue

Describe the bug
The ElementRef type is not available yet

To Reproduce
Check this Stackblitz demo where i'm importing the ElementRef from preact. In the same line render is also imported. If you hover over render you'll see the type definition of it. But that's not the case for ElementRef. It doesn't show any type definition (idk why Stackblitz isn't showing any error there. but vscode does)

Steps to reproduce the behavior:

  1. Run npm init preact elementRefDemo
  2. Check Typescript when asked
  3. Try importing ElementRef in src/index.ts from preact or preact/compact

Expected behavior
ElementRef should be available in preact or preact/compact

@PratikDev
Copy link
Author

I'm mainly integrating shadcn and finding ts issues in the shadcn provided components. i'll try to keep adding all the issues i find in this comment

KeyboardEvent is also not available.

@rschristian
Copy link
Member

rschristian commented Aug 29, 2024

I'm fairly certain KeyboardEvent is part of TS's DOM typings, it's not something we'd supply? You might have misconfiguration your tsconfig.json if it's not available.

Edit: Strange, React provides their own, but it seemingly matches the standard event? I guess we can just re-export it.

@PratikDev
Copy link
Author

Isn't it like we'll re-export most of the unavailable types from react?

@rschristian
Copy link
Member

We don't re-export anything from React, no. We do not rely on React's types for our own.

It just makes little sense to me at this moment why React provides a KeyboardEvent type, it seemingly matches the standard DOM type. See

@PratikDev
Copy link
Author

maybe i'm too noob in TS world. but when u say re-export, do u mean to re-export from TS directly?

@rschristian
Copy link
Member

rschristian commented Aug 29, 2024

Yup, assuming I'm not missing something, I believe that's all we'd do.

I'm admittedly not a big TS user myself though.

@PratikDev
Copy link
Author

u said react provides their own KeyboardEvent. it's still unclear to me why they had to do it? and even if they do, why can't we just directly use this KeyboardEvent without importing from anywhere? so that the one from TS gets used (i tried. it throws error).

@rschristian
Copy link
Member

u said react provides their own KeyboardEvent. it's still unclear to me why they had to do it?

No clue, feel free to look through the blame: source

why can't we just directly use this KeyboardEvent without importing from anywhere?

You absolutely can (and should) in user code, if it fits your needs. Won't work for libs though if they expect to pull that type from React.

@TheOrdinaryWow

This comment has been minimized.

@rschristian
Copy link
Member

Do you happen to have an example of a module that relies on the ElementRef type? We'd supply it from preact/compat, rather than preact itself, but I'd like to test that our implementation is correct.

@PratikDev
Copy link
Author

yes. as mentioned in my first comment, I was trying to use shadcn with preact. And many components in shadcn like Select and Sheet do use ElementRef

@rschristian
Copy link
Member

Thanks, was just looking for a specific component.

@rschristian
Copy link
Member

I took a look at this tonight, but looks like it might rely on #4113, which I'm not sure we can address.

Open to PRs, if anyone's got them though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants