-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
importing types from @storybook/react breaks emotion css prop types #13486
Comments
If your project depends on emotion 11 AND storybook, you'll likely encounter a type conflict. This happens because the typescript compiler will, at a certain point, while compiling/type-checking your files, load // emotion-core-stub.ts
export {} and in {
"compilerOptions": {
// ... all your existing compiler options here ...
"paths": {
"@emotion/core": ["./emotion-core-stub.ts"]
}
}
} This will prevent the conflict introduced by having emotion 10 and 11 in your project's dependency tree. |
Thanks for the tip @disintegrator! |
@disintegrator unfortunately this workaround doesn't work in CRA, since it doesn't allow overriding paths in tsconfig |
@disintegrator's stub breaks the docs plugin. I had to disable the docs plugin entirely by adding this to my // .storybook/main.js
module.exports = {
addons: [{
name: '@storybook/addon-essentials',
options: {
docs: false,
}
}]
}; |
Which TypeScript version are you using? Just tried your solution as I'm having exactly the same issue as you and I always get a TS error when type-checking the css prop. |
Hey @AndreSilva1993, I'm on TypeScript 4.1.3. |
Hi @disintegrator, I am having a very similar issue as the OP, but in our case we don't use Emotion 11.
|
I don't use This is problematic when you use a different styled-library, because you'll get a Question: Thanks |
I'm seeing a similar issue. In my case, all I did was try to add a new addon using |
* chore: init storybook * chore(storybook): configure storybook Ref: - storybookjs/storybook#13486 (comment) - emotion-js/emotion#971 * chore: update packages * chore: add ts config for sb, use webpack5 - https://storybook.js.org/docs/react/configure/typescript#mainjs-configuration - https://storybook.js.org/blog/storybook-for-webpack-5/ - https://gist.github.com/shilman/8856ea1786dcd247139b47b270912324#upgrade - storybookjs/storybook#15336 (comment) * chore: add shared components stories
This is also happening on a repo with ChakraUI and Storybook. the |
In storybook 7.0 beta we've bundled in emotion, and this should remove the possibility for conflicts like this to happen. Please let us know if this issue still exists in storybook 7.0 beta, if so please re-open. |
Describe the bug
For some odd reason, whenever types are imported from @storybook/react/types-6-0 or @storybook/react, the type definition for the css prop used in emotion will break and throw a Typescript error.
To Reproduce
Steps to reproduce the behavior:
In the provided sandbox repo:
src/stories/Button.stories.tsx
2.Uncomment import from @storybook/react
Type '({ size }: any) => SerializedStyles' is not assignable to type 'Interpolation'.
Type '({ size }: any) => SerializedStyles' is not assignable to type 'ObjectInterpolation'.
Index signature is missing in type '({ size }: any) => SerializedStyles'. TS2322
Expected behavior
the css prop should be able to take an array of functions that return SerializedStyles, without getting any Typescript error.
Screenshots
If applicable, add screenshots to help explain your problem.
Code snippets
Reproduce Repo
System
Environment Info:
System:
OS: Linux 5.8 Pop!_OS 20.10
CPU: (4) x64 Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz
Binaries:
Node: 14.15.0 - ~/.nvm/versions/node/v14.15.0/bin/node
Yarn: 1.22.5 - /usr/bin/yarn
npm: 6.14.8 - ~/.nvm/versions/node/v14.15.0/bin/npm
Browsers:
Chrome: 87.0.4280.66
Firefox: 84.0
npmPackages:
@storybook/addon-actions: ^6.1.11 => 6.1.11
@storybook/addon-essentials: ^6.1.11 => 6.1.11
@storybook/addon-links: ^6.1.11 => 6.1.11
@storybook/node-logger: ^6.1.11 => 6.1.11
@storybook/preset-create-react-app: ^3.1.5 => 3.1.5
@storybook/react: ^6.1.11 => 6.1.11
The text was updated successfully, but these errors were encountered: