stitches: React.ComponentProps not working as expected
Bug report
Describe the bug
When wanting to get the type of the props a stitches component receives, for example to be able to compose other components on top of it, React.ComponentProps<typeof StitchesComponent> is not working as expected — it’s signaling weird errors and not providing correct typings. More context in this discussion.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Go to this sandbox.
- Scroll down to the implementetion of
<LoadingButton />. - See that
<LoadingButton />has type errors. (propertyasis required). - Also, see that the props are not button-specific (see screenshot below).
Expected behavior
I expected LoadingButton to be error free with the props provided, and for prop suggestions to be button-specific.
Screenshots
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 22 (4 by maintainers)
@dbismut I’m glad that helped.
Upon further research, it appears that the issue is resolved in Emotion 11. However Storybook uses Emotion 10.
UPDATE
Having had to deal with this again, I can confirm that @derekr’s solution below of routing to an empty
*.d.tsfile is the best and easiest approach.The Fix
Here’s the less-than-ideal but better than
patch-packagefix:Step 1: Install Emotion 11
yarn add --dev @emotion/reactStep 2: Force Storybook to use Emotion 11
Force
@emotion/coreto use your updated@emotion/reactby adding this intsconfig.json:Step 3: ???
Step 4: Profit!
Not sure what the implications here are in most scenarios (I’m just using storybook), but this workaround is effective without installing
@emotion/react. You can route to an empty files.@julianbenegas thanks for raising this. in the works ⚙️
Perfect! Thanks a lot!
That’s what I thought, it used to work pre-canary (see my first post). But it doesn’t now (at least this morning). I’ll paste the type error in an hour or so.