Comments (7)
As a workaround, you can use as const
on the returned object. I suspect the reason why it fails now is that we have reordered styled
overloads.
TypeScript, currently, caches some types resolved while trying to match against the first overload. This is a long-standing issue and there is a recent-ish fix for this open here. You can even quickly verify that it does indeed fix this issue since there is a TS playground with that build available: TS playground
from emotion.
Thanks for rapid action on this! 🙏 Can confirm that as const
also fixes/hides the issue (just as as CSSObject
did)
Perhaps the issue can be fixed anyway with a new release as it forces code changes otherwise? 🤔
from emotion.
Perhaps the issue can be fixed anyway with a new release as it forces code changes otherwise? 🤔
Yeah, maybe - we have to investigate this further to determine which tradeoff is better and if we can do anything to mitigate the issue on our side without reverting the change that changed this.
from emotion.
Perhaps the issue can be fixed anyway with a new release as it forces code changes otherwise? 🤔
Yeah, maybe - we have to investigate this further to determine which tradeoff is better and if we can do anything to mitigate the issue on our side without reverting the change that changed this.
Alternatively make a release that indicates a breaking change and update documentation accordingly
from emotion.
Thanks for notifying, looking into it. Looks really strange for now, to be honest, since I can't understand why this worked before if it's broken now.
Strangely it seems to depend on which css-attributes you are styling.
Essentially, every attribute with the closed set of values (like testAlign
, which has the type Globals | "center" | "end" | "justify" | "left" | "match-parent" | "right" | "start"
) is broken, while the attribute with open set (i.e. the one which can handle any string
, like fontFamily
, which is Globals | DataType.GenericFamily | (string & {})
) works correctly.
from emotion.
Minimized example of the same error, in case someone wants to investigate too:
interface Styles {
position?: 'left';
}
type StylesCreator = () => Styles;
interface Styled {
// (creator: StylesCreator): void // uncomment this to remove error
(styles: Styles): void
(creator: StylesCreator): void
}
declare const styled: Styled
styled(() => ({ position: 'left' })) // type `string` is not assignable to type `"left"`
from emotion.
Yeah, I mentioned above that it's related to signature caching that happens when resolving the first overload. The fix would be to add a leading overload that would be capable of introducing proper contextual types for those creator functions
from emotion.
Related Issues (20)
- expect().toHaveStyleRule's target property behavior changed between v10 and v11
- using Emotion Cache adds delay to styles be applied on SSR HOT 2
- Github tagline is misleading
- Warning: Prop `className` did not match. Server: "css-j5xrcq-Component" Client: "css-13v2oeb-HomeIcon" HOT 1
- How to use mix function of css in styled? HOT 1
- @emotion/jest Styles added through the `css` prop to a styled component are not captured in snapshots
- Styled component that customizes third party library primereact is not working
- Proper CSS for client-only code in SSR mode?
- Runtime error with quoted content + !important
- Remove defaultProps copy HOT 14
- The `css` prop is not attached to a type of props if it is a disjoint union type on `className` field.
- React 19 Types Support HOT 5
- (React 19) Failing `npm i` without --legacy-peer-deps flag
- Injected styles tags HOT 1
- Browser ESM build contains references to `process` which is undefined in browser HOT 1
- @emotion/babel-plugin 11.11.x causes error: "Unexpected falsy value: undefined"
- SSR Final Build Output is including spaces when using css keyword HOT 2
- document is not defined HOT 7
- replace `html-tokenize` with other alternative, and upgrade `multipipe` to 4.x of `@emotion/server` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emotion.