Skip to content

Commit

Permalink
fix(types): change JSX.ElementType for TS 5.1+
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jun 25, 2023
1 parent 8fc2c2f commit b6c2c08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/functions/selfUpdating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export function selfUpdating<
const restoreContext = oldEffects ? forwardContext(context, true) : noop

let threw = true
let newRootNode: DefaultElement | DocumentFragment | null | undefined
let newRootNode: JSX.ElementOption
try {
newRootNode = render(props, updateProps)
if (isFunction(newRootNode)) {
Expand Down
19 changes: 10 additions & 9 deletions src/types/jsx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { ReactEventHandler, ChangeEventHandler } from './dom'
import type { Attributes, AttrWithRef } from './attr'
import type { SVGProps } from './svg'
import type { DragEventHandler } from './dom'
import { AlienEffects } from '../effects'
import type {
DetailedHTMLProps,
HTMLAttributes,
Expand Down Expand Up @@ -36,8 +35,14 @@ export declare namespace JSX {

type Children = Thunkable<JSXChild> | Children[]

type ElementOption = HTMLElement | SVGElement | false | null | undefined
type ElementsOption = ElementOption | ElementOption[]
type ElementOption =
| HTMLElement
| SVGElement
| DocumentFragment
| false
| null
| undefined

/**
* If defining the type of a component prop that can be a JSX element,
Expand All @@ -48,13 +53,9 @@ export declare namespace JSX {
type ElementProp = Thunkable<ElementOption>
type ElementsProp = Thunkable<ElementOption | ElementOption[]>

type ElementType<T> = T extends keyof IntrinsicElements
? IntrinsicElements[T]['ref'] extends
| AlienEffects<infer Element>
| undefined
? Element
: never
: never
type ElementType =
| keyof IntrinsicElements
| ((props: object) => ElementOption)

type ElementAttributes<T> = keyof IntrinsicElements extends infer TagName
? TagName extends keyof IntrinsicElements
Expand Down

0 comments on commit b6c2c08

Please sign in to comment.