question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Emotion types are polluting the global scope

See original GitHub issue

Current behavior:

The @emotion/core/types/index.d.ts file from the package includes the following declarations:

declare module 'react' {
  interface DOMAttributes<T> {
    css?: InterpolationWithTheme<any>
  }
}

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>
    }
  }
}

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 of storybook, and I didn’t know about it until I tried using the css prop for styled-components and there was no error.

Further, after including styled-components type declaration for the css prop, some strange errors emerged because of the way TypeScript handles declaration merging:

  Types of property 'css' are incompatible.
    Type 'string | CSSObject | FlattenInterpolation<ThemeProps<any>> | undefined' is not
assignable to type 'InterpolationWithTheme<any>'.
      Type 'FlattenInterpolation<ThemeProps<any>>' is not assignable to type 'InterpolationWithTheme<any>'.
        Type 'FlattenInterpolation<ThemeProps<any>>' is not assignable to type 'ObjectInterpolation<undefined>'.

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/core@10.0.27

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:15
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Andaristcommented, Jul 27, 2020

I believe I have found an appropriate fix for this on our end - if anyone wants to take a look then here it is: https://github.com/emotion-js/emotion/pull/1941 . Keep in mind that it targets the upcoming v11 that we hope to ship soon.

1reaction
Andaristcommented, Mar 13, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Climate Change and Emotions: Analysis of People's ...
Climate change involves multiple emotional expressions associated with specific labels, notably: 'concern,' 'guilt,' or 'scepticism.
Read more >
Air Pollution Reduces Interpersonal Trust: The Roles of ... - NCBI
Another study found that air pollution contributed to annoyance, dissatisfaction, worry, disgust, and other negative feelings [32]. Importantly, ...
Read more >
(PDF) Emotions in the context of environmental protection
considerations concerning emotion types, eliciting processes, and affect ... the dependent variables that are usually used (e.g. ...
Read more >
Pollution avoidance and green purchase: The role of moral ...
Self-directed moral emotions have stronger influence on pollution avoidance intention than other-directed emotions, but the effect of the other- ...
Read more >
Functions of Emotions - Noba Project
Even negative emotions are important, such as the sadness when a loved one dies, the anger when violated, the fear that overcomes us...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found