storybook: @storybook/theming causes type errors during tsc
Describe the bug
Ok this is a fun one. Basically tsc complains about missing react typings, when trying to use create of @storybook/theming.
This is because:
@storybook/themingimports@emotion/*- which in turn imports
react - which in turn requires
@types/react - which would have to be installed manually
- which would then declare global
JSXnamespace - which would then conflict with the
JSXnamespace of Vue
To Reproduce
- create Vue project with TS support via Vue CLI 3
- Storybook via vue-cli-plugin-storybook (TS conversion and config must be done by hand)
- Vue JSX/TSX typings -> https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-plugin-typescript/generator/template/src/shims-tsx.d.ts
- Create theme:
import { create } from '@storybook/theming';
export default create({
base: 'light',
brandTitle: 'My Storybook',
});
npx tsc
Expected behavior
Use create from @storybook/theming without requiring react typings and therefore no JSX namespace conflicts.
System:
- OS: any
- Device: any
- Browser: any
- Framework: vue
- Version: 5
Additional context Workaround:
- dont use storybook theming
- or dont use vue jsx/tsx
- or run tsc with
--skipLibCheck
Solution:
- provide a
createtheme function/module that does not use@emotion/* - the only stuff that
createrequires from@emotion/*isimport { css, keyframes } from '@emotion/core';inanimation.ts) - where
csstype doesnt requirereacttypings (so no problem here), but is imported from@emotion/coretypes, which importsreacttypings for other stuff (this is a problem) -> importcssfrom@emotion/css - where
keyframestype doesnt requirereacttypings (so no problem here), but its type is declared in@emotion/coretype declaration file that importsreacttypings, but actually dont use react typings forkeyframesitself (but for other stuff) -> ask for upstream change in emotion (which would maybe require some reorganisation of types/exports on their part) or reimplement/c&pkeyframesinto@storybook/themingor dont usekeyframesduringcreate
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 10
- Comments: 20 (14 by maintainers)
still relevant
@shilman it looks like the
@storybook/themingpackage doesn’t cause TS + JSX conflicts.However it seems the
@storybook/knobspackage causes this issue still as it ships@types/react-color. I’m unsure if this is intentional.The above causes the
@types/reactpackage to be installed when using the@storybook/knobspackage. If theknobsaddon can ship without this types dependency then this should resolve the Vue + TSX issues.Still have problem with JSX type conflicts, when i write stories like this:
@storybook/vueimported react JSX types@backbone87 try:
Does that solve the issue?