-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Emotion types are polluting the global scope #1800
Comments
As a workaround I think you can use a whitelist of global types by providing the |
Unfortunately this doesn't work:
... so TypeScript imports the file anyway. Now that I think of it, even if you switch to an opt-in behavior, Storybook will still need to avoid polluting the global scope by explicitly providing a type for the So for now I guess I'll stick to |
I'm going to think about how this can be solved, but if you have any ideas of your own I would highly appreciate any help with this. This is also a duplicate of #1257 |
One more thing, would you be able to prepare a minimal repro case for this? It would allow me to jump into this issue much sooner. |
Sorry, I didn't manage to find the previous issue. My suggested solution is the same as
The benefits I see here are:
Here's my smallest reproduction repo: https://github.com/fatfisz/emotion-global-type-injection-repro. |
The problem I see with that is that you would still probably bump into this issue because StoryBooks would still refer to this file and would drag this global pollution into your build, wouldn't it? |
Yes, as I mentioned previously:
But without Emotion fixing the problem first, Storybook can't do anything. I can only promise that I'll take it up with them afterwards 🙂 |
But even if we are going to fix it in a way you have proposed I'm still unsure how they could utilize css prop without polluting the global types. What would be the recommendation for them if we make css prop types opt-in? |
Each of the exported components that is actually using Emotion's import { CSSProp } from '@emotion/...'; // Just importing the type shouldn't pollute the global scope
export interface KnobControlProps<T> {
css?: CSSProp; // Just define the css prop explicitly here
knob: KnobControlConfig<T>;
onChange: (value: T) => T;
} |
Any news on this? |
I've just run into this building a component library on top of theme-ui. I have a declare global {
namespace JSX {
/**
* Do we need to modify `LibraryManagedAttributes` too,
* to make `className` props optional when `css` props is specified?
*/
interface IntrinsicAttributes {
// css?: InterpolationWithTheme<any>
}
}
} |
I have this problem with |
I believe I have found an appropriate fix for this on our end - if anyone wants to take a look then here it is: #1941 . Keep in mind that it targets the upcoming v11 that we hope to ship soon. |
A fix for this has been just merged into v11 line: #1941 |
Current behavior:
The
@emotion/core/types/index.d.ts
file from the package includes the following declarations:This causes the global scope to become polluted with
@emotion
types, even though the user might not be asking for it - eg. it came as a surprise to me, because@emotion
is a dependency ofstorybook
, and I didn't know about it until I tried using thecss
prop forstyled-components
and there was no error.Further, after including
styled-components
type declaration for thecss
prop, some strange errors emerged because of the way TypeScript handles declaration merging:Expected behavior:
I'd expect a mechanism similar to
styled-components/cssprop
: the user has to manually create a file which imports global declarations instead of pullution by default.Environment information:
@emotion/[email protected]
The text was updated successfully, but these errors were encountered: