-
Notifications
You must be signed in to change notification settings - Fork 1.2k
TypeScript typings are swallowed for most of the components #1758
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
Comments
I believe you are correct with forwardRef being the culprit, think we need to add something like |
@yamafaktory Apologies, but "present" me doesn't remember what reproduction steps "past" me did to figure out the above fix. I made a codesandbox here: https://codesandbox.io/s/sparkling-butterfly-1gvyr?file=/src/App.tsx and it looks like |
@LFDanLu Thanks a ton for the feedback and effort! Indeed your sandbox works fine. I tried to reproduce it - i.e. make it work in my private project - by upgrading to the latest TS version and React types without success. Then I noticed that the real issue is that React Spectrum uses https://www.typescriptlang.org/tsconfig#allowSyntheticDefaultImports set to true (https://github.com/adobe/react-spectrum/blob/main/tsconfig.json#L11) and then you're doing all the React imports like e.g. https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/view/src/View.tsx#L16. So basically, with It should be done like that: This is also the recommended way to do it since React as no more default export, see facebook/react#18102. TL;DR: either folks like me have to set N.B.: I'm not using Babel to transpile the code but ESBuild, that's why I was not using this option, see again https://www.typescriptlang.org/tsconfig#allowSyntheticDefaultImports:
|
Thanks for all the investigation! Will make a note to bring this up in our next planning. |
Thanks a ton @LFDanLu 🙇! |
Pretty sure this is no longer an issue. |
🐛 Bug Report
Hi folks 👋,
First of all, thanks for the massive work done on this project!
Back to the bug report: there's an issue with TypeScript's types for most of the components. It seems like
React.forwardRef
is the culprit here.🤔 Expected Behavior
All the components should expose their types correctly - i.e. no
any
.😯 Current Behavior
For example, the following
View
component - when imported - is inferred as any:https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/view/src/View.tsx#L45
Whereas a
Button
works totally fine:https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/button/src/Button.tsx#L96
💁 Possible Solution
Enforce proper types exposition (via aliasing).
🔦 Context
I encountered that while using React Spectrum in production project.
💻 Code Sample
Not relevant.
🌍 Your Environment
🧢 Your Company/Team
Not relevant.
🕷 Tracking Issue (optional)
None.
The text was updated successfully, but these errors were encountered: