diff --git a/.changeset/heavy-pets-rule.md b/.changeset/heavy-pets-rule.md new file mode 100644 index 000000000..84b813edb --- /dev/null +++ b/.changeset/heavy-pets-rule.md @@ -0,0 +1,5 @@ +--- +'@emotion/react': patch +--- + +Distribute `css` prop attachment over props that are union types diff --git a/packages/react/types/jsx-namespace.d.ts b/packages/react/types/jsx-namespace.d.ts index b43dc4fa0..ad92eaea4 100644 --- a/packages/react/types/jsx-namespace.d.ts +++ b/packages/react/types/jsx-namespace.d.ts @@ -86,8 +86,9 @@ export namespace EmotionJSX { extends ReactJSXElementAttributesProperty {} interface ElementChildrenAttribute extends ReactJSXElementChildrenAttribute {} - type LibraryManagedAttributes = WithConditionalCSSProp

& - ReactJSXLibraryManagedAttributes + type LibraryManagedAttributes = P extends unknown + ? WithConditionalCSSProp

& ReactJSXLibraryManagedAttributes + : never interface IntrinsicAttributes extends ReactJSXIntrinsicAttributes {} interface IntrinsicClassAttributes diff --git a/packages/react/types/tests.tsx b/packages/react/types/tests.tsx index e4b71ec8e..06f8785c7 100644 --- a/packages/react/types/tests.tsx +++ b/packages/react/types/tests.tsx @@ -182,6 +182,23 @@ const anim1 = keyframes` ; } +{ + const CompWithConditionalClassNameSupport = ( + _props: { foo: true; className?: string } | { foo: false } + ) => { + return null + } + ; + ; +} + { // based on the code from @types/react@17.x // https://github.com/DefinitelyTyped/DefinitelyTyped/blob/98fa4486aefd5a1916aa385402467a7157e3c73f/types/react/v17/index.d.ts#L540-L548