If you are looking for the type React.ReactNode
, it encompasses JSX.Element
as well as string
, number
, and undefined
, among others.
The relevant block of the type definitions is shown below:
type ReactText = string | number;
type ReactChild = ReactElement | ReactText;
interface ReactNodeArray extends Array<ReactNode> {}
type ReactFragment = {} | ReactNodeArray;
type ReactNode = ReactChild | ReactFragment | ReactPortal | boolean | null | undefined;
Ambiguity with Element
If you simply use the type Element
without any prefix, it will use the definition from lib.dom.ts
. The JSX
namespace in React has its own definition for JSX.Element
.
In your example, the element <div>some HTML</div>
is a JSX.Element
, which cannot be assigned to the Element
type.
function requiresElement(el: Element) {}
requiresElement(<div>some HTML</div>); // error
Argument of type 'JSX.Element' is not assignable to parameter of type 'Element'.
Type 'Element' is missing the following properties from type 'Element': attributes, classList, className, clientHeight, and 123 more.
Typescript Playground Link