Skip to content

Commit 5974e33

Browse files
authored
Fix JSX namespace @ts-ignores (#3282)
1 parent fc4d7bd commit 5974e33

File tree

1 file changed

+43
-44
lines changed

1 file changed

+43
-44
lines changed

packages/react/src/jsx-namespace.ts

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,53 @@ type WithConditionalCSSProp<P> = 'className' extends keyof P
1313
: {}
1414

1515
// unpack all here to avoid infinite self-referencing when defining our own JSX namespace for the pre-React 19 case
16-
type ReactJSXElement = true extends IsPreReact19
17-
? /** @ts-ignore */
18-
JSX.Element
19-
: /** @ts-ignore */
20-
React.JSX.Element
21-
type ReactJSXElementClass = true extends IsPreReact19
22-
? /** @ts-ignore */
23-
JSX.ElementClass
24-
: /** @ts-ignore */
25-
React.JSX.ElementClass
26-
type ReactJSXElementAttributesProperty = true extends IsPreReact19
27-
? /** @ts-ignore */
28-
JSX.ElementAttributesProperty
29-
: /** @ts-ignore */
30-
React.JSX.ElementAttributesProperty
31-
type ReactJSXElementChildrenAttribute = true extends IsPreReact19
32-
? /** @ts-ignore */
33-
JSX.ElementChildrenAttribute
34-
: /** @ts-ignore */
35-
React.JSX.ElementChildrenAttribute
36-
type ReactJSXLibraryManagedAttributes<C, P> = true extends IsPreReact19
37-
? /** @ts-ignore */
38-
JSX.LibraryManagedAttributes<C, P>
39-
: /** @ts-ignore */
40-
React.JSX.LibraryManagedAttributes<C, P>
41-
type ReactJSXIntrinsicAttributes = true extends IsPreReact19
42-
? /** @ts-ignore */
43-
JSX.IntrinsicAttributes
44-
: /** @ts-ignore */
45-
React.JSX.IntrinsicAttributes
46-
type ReactJSXIntrinsicClassAttributes<T> = true extends IsPreReact19
47-
? /** @ts-ignore */
48-
JSX.IntrinsicClassAttributes<T>
49-
: /** @ts-ignore */
50-
React.JSX.IntrinsicClassAttributes<T>
51-
type ReactJSXIntrinsicElements = true extends IsPreReact19
52-
? /** @ts-ignore */
53-
JSX.IntrinsicElements
54-
: /** @ts-ignore */
55-
React.JSX.IntrinsicElements
16+
17+
// the IsPreReact19 and @ts-ignore comments are to allow @emotion/react to support three different cases of types
18+
// - pre-React 18.something which didn't have `React.JSX`
19+
// - React 18.something with `React.JSX`
20+
// - React 19 with `React.JSX` and no global `JSX`
21+
// we support both pre-React 19 cases by using the global `JSX` and with the React 19 types, we use `React.JSX`
22+
// to make this work, we need @ts-ignore comments to ignore references that are invalid
23+
// though note that the error types resulting from ignoring the errors will never be used
24+
// since the pre vs post React 19 conditional will pick the one that won't error
25+
26+
// prettier-ignore
27+
/** @ts-ignore */
28+
type ReactJSXElement = true extends IsPreReact19 ? JSX.Element : React.JSX.Element
29+
30+
// prettier-ignore
31+
/** @ts-ignore */
32+
type ReactJSXElementClass = true extends IsPreReact19 ? JSX.ElementClass : React.JSX.ElementClass
33+
34+
// prettier-ignore
35+
/** @ts-ignore */
36+
type ReactJSXElementAttributesProperty = true extends IsPreReact19 ? JSX.ElementAttributesProperty : React.JSX.ElementAttributesProperty
37+
38+
// prettier-ignore
39+
/** @ts-ignore */
40+
type ReactJSXElementChildrenAttribute = true extends IsPreReact19 ? JSX.ElementChildrenAttribute : React.JSX.ElementChildrenAttribute
41+
42+
// prettier-ignore
43+
/** @ts-ignore */
44+
type ReactJSXLibraryManagedAttributes<C, P> = true extends IsPreReact19 ? JSX.LibraryManagedAttributes<C, P> : React.JSX.LibraryManagedAttributes<C, P>
45+
46+
// prettier-ignore
47+
/** @ts-ignore */
48+
type ReactJSXIntrinsicAttributes = true extends IsPreReact19 ? JSX.IntrinsicAttributes : React.JSX.IntrinsicAttributes
49+
50+
// prettier-ignore
51+
/** @ts-ignore */
52+
type ReactJSXIntrinsicClassAttributes<T> = true extends IsPreReact19 ? JSX.IntrinsicClassAttributes<T> : React.JSX.IntrinsicClassAttributes<T>
53+
54+
// prettier-ignore
55+
/** @ts-ignore */
56+
type ReactJSXIntrinsicElements = true extends IsPreReact19 ? JSX.IntrinsicElements : React.JSX.IntrinsicElements
5657

5758
// based on the code from @types/react@18.2.8
5859
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/3197efc097d522c4bf02b94e1a0766d007d6cdeb/types/react/index.d.ts#LL3204C13-L3204C13
60+
// prettier-ignore
5961
/** @ts-ignore */
60-
type ReactJSXElementType = true extends IsPreReact19
61-
? string | React.JSXElementConstructor<any>
62-
: /** @ts-ignore */
63-
React.JSX.ElementType
62+
type ReactJSXElementType = true extends IsPreReact19 ? string | React.JSXElementConstructor<any> : React.JSX.ElementType
6463

6564
export namespace ReactJSX {
6665
export type ElementType = ReactJSXElementType

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy