You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type parameter on higher-order-component doesn't seem to work #28720
src/wrappedComponent.tsx:10:21 - error TS2322: Type '{ foo: number; }' is not assignable to type 'IntrinsicAttributes & P & { children?: ReactNode; }'.
Property 'foo' does not exist on type 'IntrinsicAttributes & P & { children?: ReactNode; }'.
10 return <WrappedComponent foo={0} />;
We corrected & tightened up our checking of generics in jsx - we had a nasty habit of erasing them before.
You're declaring that your WrappedComponent takes a P extends ComponentProps, but are only providing a ComponentProps to the WrappedComponent when its type states that you must provide a P. Usually you'd do this by spreading the input props to SomeHOC into your WrappedComponent tag.
Got it. The actual (non-example) code was using some cached props in the state, of type ComponentProps. By making the state itself similarly generic, it works.
Activity
weswigham commentedon Nov 29, 2018
We corrected & tightened up our checking of generics in jsx - we had a nasty habit of erasing them before.
You're declaring that your
WrappedComponenttakes aP extends ComponentProps, but are only providing aComponentPropsto theWrappedComponentwhen its type states that you must provide aP. Usually you'd do this by spreading the input props toSomeHOCinto yourWrappedComponenttag.MLoughry commentedon Nov 29, 2018
Got it. The actual (non-example) code was using some cached props in the state, of type
ComponentProps. By making the state itself similarly generic, it works.