@@ -9,7 +9,7 @@ import type {Schema} from 'property-information'
9
9
/**
10
10
* Child.
11
11
*/
12
- export type Child = JSX . Element | string | null | undefined
12
+ export type Child = JsxElement | string | null | undefined
13
13
14
14
/**
15
15
* Possible components to use.
@@ -24,16 +24,16 @@ export type Child = JSX.Element | string | null | undefined
24
24
// Note: this type has to be in `.ts` or `.d.ts`, otherwise TSC hardcodes
25
25
// react into the `.d.ts` file.
26
26
export type Components = {
27
- [ TagName in keyof JSX . IntrinsicElements ] :
28
- | Component < JSX . IntrinsicElements [ TagName ] & ExtraProps >
29
- | keyof JSX . IntrinsicElements
27
+ [ TagName in keyof JsxIntrinsicElements ] :
28
+ | Component < JsxIntrinsicElements [ TagName ] & ExtraProps >
29
+ | keyof JsxIntrinsicElements
30
30
}
31
31
32
32
/**
33
33
* Function or class component.
34
34
*
35
- * You can access props at `JSX.IntrinsicElements `.
36
- * For example, to find props for `a`, use `JSX.IntrinsicElements ['a']`.
35
+ * You can access props at `JsxIntrinsicElements `.
36
+ * For example, to find props for `a`, use `JsxIntrinsicElements ['a']`.
37
37
*
38
38
* @typeParam ComponentProps
39
39
* Props type.
@@ -55,7 +55,7 @@ export type Create = (
55
55
type : unknown ,
56
56
props : Props ,
57
57
key : string | undefined
58
- ) => JSX . Element
58
+ ) => JsxElement
59
59
60
60
/**
61
61
* Class component: given props, returns an instance.
@@ -69,7 +69,7 @@ export type Create = (
69
69
*/
70
70
type ClassComponent < ComponentProps > = new (
71
71
props : ComponentProps
72
- ) => JSX . ElementClass
72
+ ) => JsxElementClass
73
73
74
74
/**
75
75
* Casing to use for attribute names.
@@ -135,18 +135,31 @@ export type Fragment = unknown
135
135
*/
136
136
type FunctionComponent < ComponentProps > = (
137
137
props : ComponentProps
138
- ) => JSX . Element | string | null | undefined
138
+ ) => JsxElement | string | null | undefined
139
139
140
140
/**
141
- * Create a production element .
141
+ * Conditional type for a class .
142
142
*/
143
- export type Jsx = (
144
- // `any` because runtimes often have complex framework-specific types here.
145
- // type-coverage:ignore-next-line
146
- type : any ,
147
- props : Props ,
148
- key ?: string | undefined
149
- ) => JSX . Element
143
+ // @ts -ignore: conditionally defined.
144
+ export type JsxElementClass = any extends JSX . ElementClass
145
+ ? unknown
146
+ : // @ts -ignore: conditionally defined.
147
+ JSX . ElementClass
148
+
149
+ /**
150
+ * Conditional type for a node object.
151
+ */
152
+ // @ts -ignore: conditionally defined.
153
+ export type JsxElement = any extends JSX . Element ? unknown : JSX . Element
154
+
155
+ /**
156
+ * Conditional type for a record of tag names to corresponding props.
157
+ */
158
+ // @ts -ignore: conditionally defined.
159
+ export type JsxIntrinsicElements = any extends JSX . IntrinsicElements
160
+ ? Record < PropertyKey , any >
161
+ : // @ts -ignore: conditionally defined.
162
+ JSX . IntrinsicElements
150
163
151
164
/**
152
165
* Create a development element.
@@ -160,7 +173,18 @@ export type JsxDev = (
160
173
isStaticChildren : boolean ,
161
174
source : Source ,
162
175
self : undefined
163
- ) => JSX . Element
176
+ ) => JsxElement
177
+
178
+ /**
179
+ * Create a production element.
180
+ */
181
+ export type Jsx = (
182
+ // `any` because runtimes often have complex framework-specific types here.
183
+ // type-coverage:ignore-next-line
184
+ type : any ,
185
+ props : Props ,
186
+ key ?: string | undefined
187
+ ) => JsxElement
164
188
165
189
/**
166
190
* Configuration.
@@ -232,10 +256,6 @@ export interface OptionsDevelopment extends OptionsBase {
232
256
* Whether to use `jsxDEV` (when on) or `jsx` and `jsxs` (when off).
233
257
*/
234
258
development : true
235
- /**
236
- * Dynamic JSX (optional).
237
- */
238
- jsx ?: Jsx | null | undefined
239
259
/**
240
260
* Development JSX.
241
261
*/
@@ -244,6 +264,10 @@ export interface OptionsDevelopment extends OptionsBase {
244
264
* Static JSX (optional).
245
265
*/
246
266
jsxs ?: Jsx | null | undefined
267
+ /**
268
+ * Dynamic JSX (optional).
269
+ */
270
+ jsx ?: Jsx | null | undefined
247
271
}
248
272
249
273
/**
@@ -258,10 +282,6 @@ export interface OptionsProduction extends OptionsBase {
258
282
* Whether to use `jsxDEV` (when on) or `jsx` and `jsxs` (when off) (optional).
259
283
*/
260
284
development ?: false | null | undefined
261
- /**
262
- * Dynamic JSX.
263
- */
264
- jsx : Jsx
265
285
/**
266
286
* Development JSX (optional).
267
287
*/
@@ -270,6 +290,10 @@ export interface OptionsProduction extends OptionsBase {
270
290
* Static JSX.
271
291
*/
272
292
jsxs : Jsx
293
+ /**
294
+ * Dynamic JSX.
295
+ */
296
+ jsx : Jsx
273
297
}
274
298
275
299
/**
0 commit comments