Skip to content

fix: explicitly define children prop for React 19 compatibility#372

Open
jctf wants to merge 1 commit intopacocoursey:mainfrom
jctf:fix/react-19-children-types
Open

fix: explicitly define children prop for React 19 compatibility#372
jctf wants to merge 1 commit intopacocoursey:mainfrom
jctf:fix/react-19-children-types

Conversation

@jctf
Copy link

@jctf jctf commented Oct 23, 2025

Fixes #367

React 19 introduced changes to how PropsWithChildren works in the type system, causing TypeScript errors when using
ThemeProvider with children:

Type '{ children: Element; ... }' is not assignable to type 'IntrinsicAttributes & ThemeProviderProps'.                   
  Property 'children' does not exist on type 'IntrinsicAttributes & ThemeProviderProps'.                                  

Solution

This PR explicitly defines the children prop as React.ReactNode instead of extending PropsWithChildren<unknown>.

Changes:

- export interface ThemeProviderProps extends React.PropsWithChildren<unknown> {                                          
+ export interface ThemeProviderProps {                                                                                   
+   /** Children elements to be wrapped by the theme provider */                                                          
+   children?: React.ReactNode                                                                                            

Backward Compatibility

This change is fully backward compatible with React 16.8+, 17, and 18:

  • React.ReactNode has been stable since React 16+
  • Explicitly defining children?: React.ReactNode is functionally equivalent to PropsWithChildren<unknown> in older
    React versions
  • All examples in this repo (using React 18.2.0) build successfully with this change
  • Only type definitions changed - no runtime behaviour changes

Fixes pacocoursey#367

React 19 changed how `PropsWithChildren` works in the type system,
causing TypeScript errors when using ThemeProvider with children.

This change explicitly defines the `children` prop as `React.ReactNode`
instead of extending `PropsWithChildren<unknown>`, which resolves the
compatibility issue while maintaining backward compatibility.

The change:
- Removes `extends React.PropsWithChildren<unknown>`
- Adds explicit `children?: React.ReactNode` property

This ensures the component works correctly with both React 18 and React 19.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Property 'children' does not exist on type 'ThemeProviderProps' in React 19

4 participants