Skip to content

WIP: Components, Element: Keep React types out of emitted declarations - #84526

Draft
yyppsk wants to merge 1 commit into
WordPress:trunkfrom
yyppsk:fix/react-18-type-declarations
Draft

yyppsk wants to merge 1 commit into
WordPress:trunkfrom
yyppsk:fix/react-18-type-declarations

Conversation

@yyppsk

@yyppsk yyppsk commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

What?

Fixes the published type declarations of @wordpress/components and @wordpress/element so they type-check with @types/react 18 again.

Closes #84464

Why?

The packages' peer ranges allow @types/react ^18 || ^19, but since the React 19 upgrade their .d.ts files reference React 19-only types (SubmitEventHandler, ToggleEventHandler, and the two-parameter ChangeEventHandler<T, U>). A React 18 consumer using skipLibCheck: false gets ~180 errors from @wordpress/components@42.

Hooks that destructure ...otherProps and spread them into their return value have no nameable return type, so TypeScript writes every DOM attribute from the @types/react version used at build time into the declarations. The private PolymorphicIntrinsicProps type is inlined the same way into every contextConnect component (e.g. BaseControl), and so is RawHTML's inferred createElement return type.

How?

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

Before After

Use of AI Tools

Exact this MD with solution approach, and follow exact md given here

Hooks that spread their remaining props, and the private
`PolymorphicIntrinsicProps` type, had no name TypeScript could reference,
so the emitted declarations inlined every DOM attribute from the
`@types/react` version used at build time. Since the React 19 upgrade, that
put React 19-only types (`SubmitEventHandler`, `ToggleEventHandler`, the
two-parameter `ChangeEventHandler`) into the published declarations, which
fail to type-check with `@types/react` 18 despite the `^18 || ^19` peer
ranges.

- Add a `HookReturnProps` helper type and give each affected hook an
  explicit return type built on `WordPressComponentProps`.
- Export `PolymorphicIntrinsicProps` so `contextConnect` declarations
  reference it by name.
- Declare `RawHTML`'s return type as `React.ReactElement`.

See WordPress#84464.
@github-actions github-actions Bot added [Package] Element /packages/element [Package] Components /packages/components labels Oct 11, 2026
@github-actions

Copy link
Copy Markdown

🤖 PR meta 🤖

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

@yyppsk
yyppsk force-pushed the fix/react-18-type-declarations branch from 257b6f8 to 925d946 Compare October 11, 2026 17:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Package] Element /packages/element

Projects

None yet

Development

Successfully merging this pull request may close these issues.

React 19 types are being partially forced despite React 18 compatibility

1 participant