Skip to content

Commit

Permalink
Undeprecate Global React JSX Namespace
Browse files Browse the repository at this point in the history
DefinitelyTyped#64464 (landed in semver patch release `@types/react@18.2.6`) scopes the JSX namespace as `React.JSX` to avoid collisions with multiple libraries working in the JSX namespace.

This change also deprecated the existing JSX namespace, so existing usages of `JSX.Element`, etc are flagged in-editor.

<img width="686" alt="Screenshot 2023-07-25 at 14 11 59" src="https://github.com/facebook/react-native/assets/4661784/531a4f88-8090-43aa-86d6-4af595d4cb5d"> 

This has a pretty drastic effect of making every previous non-anonymous function component, with an explicit return type, now fire deprecation warnings. E.g. this patch update now makes the out-of-the-box React native template create deprecation warnings. facebook/react-native#38615

In DefinitelyTyped itself, the hundreds of packages using `JSX.Element` outside of the direct React typings were not updated. TypeScript's [own documentation](https://www.typescriptlang.org/docs/handbook/jsx.html) also still suggests using `JSX.Element`. This is echoed by a platitude of existing documentation, and googling for `React.JSX.Element` will just bring up information about `JSX.Element`.

Due to the widespread nature of the breakage here (especially in a patch release), and disconnect with existing code, documentation, and resources, this change removes the `@deprecated` annotation. I think there might still be a possible path to discouraging usage, but there needs to be a lot of legwork to get there in a way which isn't disruptive.
  • Loading branch information
NickGerleman authored Jul 25, 2023
1 parent de66435 commit b2bc282
Showing 1 changed file with 0 additions and 3 deletions.
3 changes: 0 additions & 3 deletions types/react/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3220,9 +3220,6 @@ type ReactManagedAttributes<C, P> = C extends { propTypes: infer T; defaultProps
: P;

declare global {
/**
* @deprecated Use `React.JSX` instead of the global `JSX` namespace.
*/
namespace JSX {
// We don't just alias React.ElementType because React.ElementType
// historically does more than we need it to.
Expand Down

0 comments on commit b2bc282

Please sign in to comment.