Skip to content

Commit 0ce3ed0

Browse files
Distribute css prop attachment over props that are union types (#3232)
* 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]>
1 parent e819f9c commit 0ce3ed0

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

.changeset/heavy-pets-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@emotion/react': patch
3+
---
4+
5+
Distribute `css` prop attachment over props that are union types

packages/react/types/jsx-namespace.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ export namespace EmotionJSX {
8686
extends ReactJSXElementAttributesProperty {}
8787
interface ElementChildrenAttribute extends ReactJSXElementChildrenAttribute {}
8888

89-
type LibraryManagedAttributes<C, P> = WithConditionalCSSProp<P> &
90-
ReactJSXLibraryManagedAttributes<C, P>
89+
type LibraryManagedAttributes<C, P> = P extends unknown
90+
? WithConditionalCSSProp<P> & ReactJSXLibraryManagedAttributes<C, P>
91+
: never
9192

9293
interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {}
9394
interface IntrinsicClassAttributes<T>

packages/react/types/tests.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,23 @@ const anim1 = keyframes`
182182
;<CompWithoutProps css={{ backgroundColor: 'hotpink' }} />
183183
}
184184

185+
{
186+
const CompWithConditionalClassNameSupport = (
187+
_props: { foo: true; className?: string } | { foo: false }
188+
) => {
189+
return null
190+
}
191+
;<CompWithConditionalClassNameSupport
192+
foo={true}
193+
css={{ backgroundColor: 'hotpink' }}
194+
/>
195+
;<CompWithConditionalClassNameSupport
196+
foo={false}
197+
// $ExpectError
198+
css={{ backgroundColor: 'hotpink' }}
199+
/>
200+
}
201+
185202
{
186203
// based on the code from @types/[email protected]
187204
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/98fa4486aefd5a1916aa385402467a7157e3c73f/types/react/v17/index.d.ts#L540-L548

0 commit comments

Comments
 (0)