Skip to content

Commit 9357f33

Browse files
naari3Andarist
andauthoredJun 7, 2023
Added ElementType to the Emotion's JSX namespace (#3048)
* Support JSX.ElementType * Reexport ElementType * Remove failing test case due to type safe concerns see also: #3048 (comment) * Create wicked-boxes-lick.md --------- Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
1 parent 1135f8e commit 9357f33

File tree

4 files changed

+11
-16
lines changed

4 files changed

+11
-16
lines changed
 

‎.changeset/wicked-boxes-lick.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@emotion/react": patch
3+
---
4+
5+
Added `ElementType` to the Emotion's `JSX` namespace. It's defined in the same way as the one in `@types/react` and should make it possible to use components that return `string`s, `Promise`s and other types that are valid in React.

‎packages/react/types/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export function ClassNames(props: ClassNamesProps): ReactElement
9696
export const jsx: typeof createElement
9797
export namespace jsx {
9898
namespace JSX {
99+
type ElementType = EmotionJSX.ElementType
99100
interface Element extends EmotionJSX.Element {}
100101
interface ElementClass extends EmotionJSX.ElementClass {}
101102
interface ElementAttributesProperty

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

+5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ type ReactJSXIntrinsicAttributes = JSX.IntrinsicAttributes
1818
type ReactJSXIntrinsicClassAttributes<T> = JSX.IntrinsicClassAttributes<T>
1919
type ReactJSXIntrinsicElements = JSX.IntrinsicElements
2020

21+
// based on the code from @types/react@18.2.8
22+
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/3197efc097d522c4bf02b94e1a0766d007d6cdeb/types/react/index.d.ts#LL3204C13-L3204C13
23+
type ReactJSXElementType = string | React.JSXElementConstructor<any>
24+
2125
export namespace EmotionJSX {
26+
type ElementType = ReactJSXElementType
2227
interface Element extends ReactJSXElement {}
2328
interface ElementClass extends ReactJSXElementClass {}
2429
interface ElementAttributesProperty

‎packages/react/types/tests.tsx

-16
Original file line numberDiff line numberDiff line change
@@ -245,19 +245,3 @@ const anim1 = keyframes`
245245
? true
246246
: false
247247
}
248-
249-
// RMWC-like component test
250-
declare const OtherComponent: {
251-
<Tag extends React.ElementType>(
252-
props:
253-
| React.AllHTMLAttributes<HTMLInputElement>
254-
| React.ComponentPropsWithRef<Tag>,
255-
ref: any
256-
): JSX.Element
257-
displayName?: string
258-
}
259-
;<OtherComponent
260-
onChange={ev => {
261-
console.log(ev.currentTarget.value)
262-
}}
263-
/>

0 commit comments

Comments
 (0)
Please sign in to comment.