Skip to content

Commit

Permalink
Distribute css prop attachment over props that are union types (#3232)
Browse files Browse the repository at this point in the history
* Let 'css' prop attachment be distributed over union types.

* Add a test case to check LibraryManagedAttributes distributes over unions.

* Fix the test case

* Delete unused imports

* Replace with an integration test

* Update .changeset/heavy-pets-rule.md

---------

Co-authored-by: Mateusz Burzyński <[email protected]>
  • Loading branch information
ENvironmentSet and Andarist authored Aug 5, 2024
1 parent e819f9c commit 0ce3ed0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-pets-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/react': patch
---

Distribute `css` prop attachment over props that are union types
5 changes: 3 additions & 2 deletions packages/react/types/jsx-namespace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ export namespace EmotionJSX {
extends ReactJSXElementAttributesProperty {}
interface ElementChildrenAttribute extends ReactJSXElementChildrenAttribute {}

type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
ReactJSXLibraryManagedAttributes<C, P>
type LibraryManagedAttributes<C, P> = P extends unknown
? WithConditionalCSSProp<P> & ReactJSXLibraryManagedAttributes<C, P>
: never

interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {}
interface IntrinsicClassAttributes<T>
Expand Down
17 changes: 17 additions & 0 deletions packages/react/types/tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,23 @@ const anim1 = keyframes`
;<CompWithoutProps css={{ backgroundColor: 'hotpink' }} />
}

{
const CompWithConditionalClassNameSupport = (
_props: { foo: true; className?: string } | { foo: false }
) => {
return null
}
;<CompWithConditionalClassNameSupport
foo={true}
css={{ backgroundColor: 'hotpink' }}
/>
;<CompWithConditionalClassNameSupport
foo={false}
// $ExpectError
css={{ backgroundColor: 'hotpink' }}
/>
}

{
// based on the code from @types/[email protected]
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/98fa4486aefd5a1916aa385402467a7157e3c73f/types/react/v17/index.d.ts#L540-L548
Expand Down

0 comments on commit 0ce3ed0

Please sign in to comment.