preactjs / preact

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
https://preactjs.com
MIT License
36.56k stars 1.95k forks source link

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

Open PratikDev opened 2 weeks ago

PratikDev commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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

rschristian commented 2 weeks ago

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 commented 2 weeks ago

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

rschristian commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 1 week ago

Just met the same issue here, waiting for a solution.

rschristian commented 1 week ago

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 commented 6 days ago

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 commented 6 days ago

Thanks, was just looking for a specific component.

rschristian commented 3 days ago

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.