Description
Edit: If you have issues but you did NOT upgrade to 18, or if you upgraded but get confusing errors from dependencies, the problem is likely that some library (incorrectly) specifies @types/react
as a dependency with version *
rather than an optional peer dependency. Find which library it is and file an issue for it. See #24304 (comment) for diagnostics and common workarounds.
A few hours ago, a major version of React types for Typescript was released.
I have tried to test this right away to see if there are any changes that require adaptation in my own projects.
Due to a very large number of users using React's type library (we use fundamental types like React.FC by the hundreds in our own projects), it's reasonable to question whether there's been a small mistake here.
Specifically, the following type declaration still exists in the 18 release.
type PropsWithChildren<P> = P & { children?: ReactNode | undefined };
However, this is no longer used in the library, at least not when looking at the diff
DefinitelyTyped/DefinitelyTyped@55dc209
A quick search on Github yields millions of hits that use the type alias React.FC to the actual type React.FunctionalComponent.
Before
interface FunctionComponent<P = {}> {
(props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
...
}
Now
interface FunctionComponent<P = {}> {
(props: P, context?: any): ReactElement<any, any> | null;
}
I think matching very, very many places in a single project doesn't seem to do justice to the change made; always the property children?: ReactNode to be redefined is definitely too much effort.
Positions at which PropsWithChildren were used before
- FunctionComponent, as shown in the example
- ForwardRefRenderFunction,
- und das Funktions-Interface propsAreEqual von memo
Thx!