Declaring JSX types in TypeScript 5.1
Blog post from LogRocket
TypeScript 5.1 introduces a significant new feature called "decoupled type-checking between JSX elements and JSX tag types," which provides libraries with the ability to control the types used for JSX elements. This feature addresses a longstanding issue where TypeScript was unable to fully represent the range of possibilities offered by JSX, particularly in libraries like React. Previously, TypeScript restricted function components to return only JSX.Element or null, but with the introduction of JSX.ElementType, it can now accommodate a broader range of return types, such as ReactNode. This development allows function components to return values like numbers, enhancing the flexibility of JSX in TypeScript. The feature, primarily beneficial for library and type definition authors, signifies a step forward in aligning TypeScript's type system with the evolving capabilities of JSX, ensuring better compatibility and more control over component types.