@@ -9,7 +9,7 @@ import type {Schema} from 'property-information'
99/**
1010 * Child.
1111 */
12- export type Child = JSX . Element | string | null | undefined
12+ export type Child = JsxElement | string | null | undefined
1313
1414/**
1515 * Possible components to use.
@@ -24,16 +24,16 @@ export type Child = JSX.Element | string | null | undefined
2424// Note: this type has to be in `.ts` or `.d.ts`, otherwise TSC hardcodes
2525// react into the `.d.ts` file.
2626export 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
3030}
3131
3232/**
3333 * Function or class component.
3434 *
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']`.
3737 *
3838 * @typeParam ComponentProps
3939 * Props type.
@@ -55,7 +55,7 @@ export type Create = (
5555 type : unknown ,
5656 props : Props ,
5757 key : string | undefined
58- ) => JSX . Element
58+ ) => JsxElement
5959
6060/**
6161 * Class component: given props, returns an instance.
@@ -69,7 +69,7 @@ export type Create = (
6969 */
7070type ClassComponent < ComponentProps > = new (
7171 props : ComponentProps
72- ) => JSX . ElementClass
72+ ) => JsxElementClass
7373
7474/**
7575 * Casing to use for attribute names.
@@ -135,18 +135,31 @@ export type Fragment = unknown
135135 */
136136type FunctionComponent < ComponentProps > = (
137137 props : ComponentProps
138- ) => JSX . Element | string | null | undefined
138+ ) => JsxElement | string | null | undefined
139139
140140/**
141- * Create a production element .
141+ * Conditional type for a class .
142142 */
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
150163
151164/**
152165 * Create a development element.
@@ -160,7 +173,18 @@ export type JsxDev = (
160173 isStaticChildren : boolean ,
161174 source : Source ,
162175 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
164188
165189/**
166190 * Configuration.
@@ -232,10 +256,6 @@ export interface OptionsDevelopment extends OptionsBase {
232256 * Whether to use `jsxDEV` (when on) or `jsx` and `jsxs` (when off).
233257 */
234258 development : true
235- /**
236- * Dynamic JSX (optional).
237- */
238- jsx ?: Jsx | null | undefined
239259 /**
240260 * Development JSX.
241261 */
@@ -244,6 +264,10 @@ export interface OptionsDevelopment extends OptionsBase {
244264 * Static JSX (optional).
245265 */
246266 jsxs ?: Jsx | null | undefined
267+ /**
268+ * Dynamic JSX (optional).
269+ */
270+ jsx ?: Jsx | null | undefined
247271}
248272
249273/**
@@ -258,10 +282,6 @@ export interface OptionsProduction extends OptionsBase {
258282 * Whether to use `jsxDEV` (when on) or `jsx` and `jsxs` (when off) (optional).
259283 */
260284 development ?: false | null | undefined
261- /**
262- * Dynamic JSX.
263- */
264- jsx : Jsx
265285 /**
266286 * Development JSX (optional).
267287 */
@@ -270,6 +290,10 @@ export interface OptionsProduction extends OptionsBase {
270290 * Static JSX.
271291 */
272292 jsxs : Jsx
293+ /**
294+ * Dynamic JSX.
295+ */
296+ jsx : Jsx
273297}
274298
275299/**
0 commit comments