Skip to content

[react] Add module augmentation target to restore implicit children#59751

Closed
eps1lon wants to merge 2 commits intoDefinitelyTyped:masterfrom
eps1lon:feat/react/baseprops-module-augmentation
Closed

[react] Add module augmentation target to restore implicit children#59751
eps1lon wants to merge 2 commits intoDefinitelyTyped:masterfrom
eps1lon:feat/react/baseprops-module-augmentation

Conversation

@eps1lon
Copy link
Copy Markdown
Collaborator

@eps1lon eps1lon commented Apr 7, 2022

Allows restoring implicit children like we had with React 17. This should ease migration pain.

import * as React from 'react'

// include once via `tsconfig.json`
declare module 'react' {
    export interface ComponentTypeBaseProps {
        children?: React.ReactNode;
    }
}

// implicit children are back in every file!
const Component: React.FC = ({children}) => {
    return <div>Implicit children! {children}</div>
}

Playground Link

This also allows implicit children for React.forwardRef which was frequently requested ( #32785, #48420, #52604, #50436, #33602).

Need to test locally first. I don't think we can add automated tests since module augmentation is permanent.

Comment thread types/react/index.d.ts
* To restore that behavior you can augment `ComponentTypeBaseProps` with `children`:
* @link https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEIcA5FDvmQFA0AmWuANspXCBPQK7NbmU8MMnADeNOJLhYAHpFhxgAOxhYoBPPwDCJSEqwqAKgE8wWAEJosABWJh04qU7i4AFsGb1KSgPwAuTCoYADpsIQA5LiwAbgkpAF8aRJpcCCVUeB1wNIMYALD8YIAxLTgAXjgAClE3Dy8DeIBKcoA+MTjJShhuKCU4AB56YAA3FoBJcGZgXGB4Ws9vAEIxefqleP6AeiHRpKA
*/
interface ComponentTypeBaseProps {}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interface ComponentTypeBaseProps {}
interface ComponentTypeCommonProps {}

@eps1lon eps1lon force-pushed the feat/react/baseprops-module-augmentation branch from 9363284 to 31771ff Compare April 9, 2022 08:14
@eps1lon
Copy link
Copy Markdown
Collaborator Author

eps1lon commented Jun 16, 2022

This won't work since it disables excess prop checking.

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.

2 participants