Skip to content

feat(react-utilities): add custom JSX.* types that are compatible with various react major versions - #34733

Merged
Martin Hochel (Hotell) merged 11 commits into
microsoft:masterfrom
Hotell:v9/jsx-namespace-compat-types
Jul 25, 2025
Merged

Martin Hochel (Hotell) merged 11 commits into
microsoft:masterfrom
Hotell:v9/jsx-namespace-compat-types

Conversation

@Hotell

@Hotell Martin Hochel (Hotell) commented Jun 26, 2025 •

Copy link
Copy Markdown
Contributor

Previous Behavior

New Behavior

1. Introduces React major versions agnostic JSX.* namespace types exposed as public api of react-utilities

  • replaces keyof JSX.IntrinsicElements/keyof React.JSX.IntrinsicElements with JSXIntrinsicElementKeys
  • replaces JSX.IntrinsicElement[T]/React.JSX.IntrinsicElement[T] (index accessor) with JSXIntrinsicElement<Element>
  • replaces JSX.Element/React.JSX.Element with JSXElement

Before:

const renderFoo: (): JSX.Element => <div>Hello</div>

interface SomeElementProps {
 as?: keyof JSX.IntrinsicElements;
 divProps?: JSX.IntrinsicElements['div'];
}

After:

import type { JSXElement, JSXIntrinsicElementKeys, JSXIntrinsicElement } from '@fluentui/react-utilities';

const renderFoo: (): JSXElement => <div>Hello</div>

interface SomeElementProps {
 as?: JSXIntrinsicElementKeys;
 divProps?: JSXIntrinsicElement<'div'>;
}

2. replaces keyof JSX.IntrinsicElements and JSX.IntrinsicElements['div'] with our new types within v9

  • react-aria
  • react-utilities
  • react-migration-v0-v9
  • react-motion

Technical Details

These types are auto-generated on every react-utilitites build - making it always in sync.

Example of running nx run react-utilities:build:

example of running nx run react-utilities:build to showcase auto generation
  • existing @types/react installed within node_modules are fetched.
  • types are processed by tsc checker to unwrap type value of keyof JSX.IntrinsicElement
  • we emit the unwrapped definition to src/utils/generated-types.ts
  • all symbols are re-exported from src/utils/types.ts

Follow up

  • replace all deprecated JSX.Element occurrences with custom JSXElement in all v9

Related Issue(s)

@Hotell Martin Hochel (Hotell) changed the title feat(react-utilities): add custom JSX types that are compatible with various react major versions feat(react-utilities): add custom JSX.* types that are compatible with various react major versions Jun 27, 2025
@github-actions

github-actions Bot commented Jun 27, 2025 •

Copy link
Copy Markdown

📊 Bundle size report

✅ No changes found

@github-actions

Copy link
Copy Markdown

Pull request demo site: URL

@Hotell
Martin Hochel (Hotell) marked this pull request as ready for review July 10, 2025 13:21
@Hotell
Martin Hochel (Hotell) requested review from a team as code owners July 10, 2025 13:21
@Hotell

Copy link
Copy Markdown
Contributor Author

can we get review on this one please ? Oleksandr Fediashov (@layershifter) Robert Penner (@robertpenner)

…ditional based on react version used to support full type soundness based on react version used
@Hotell
Martin Hochel (Hotell) force-pushed the v9/jsx-namespace-compat-types branch from 5122a88 to 139a4f8 Compare July 24, 2025 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants