javascript - T not assignable to Readonly<T> -
ts version 2.4.2
i'm making react component decorator enhances component custom props. want maintain types of component. minimal working example:
import * react 'react'; type required = { kek: string }; type props<t> = required & t; function decorator<t>(component: react.componenttype<props<t>>): react.componenttype<t> { class wrapper extends react.component<props<t>, {}> { props: props<t>; render() { // sfc , component conflict return react.createelement(component any, this.props); } } return wrapper; }
however, ts complains on wrapper
class that:
error:(7, 9) ts2415:class 'wrapper' incorrectly extends base class 'component<props<t>, {}>'. types of property 'props' incompatible. type 'props<t>' not assignable type 'readonly<{ children?: reactnode; }> & readonly<props<t>>'. type 'props<t>' not assignable type 'readonly<props<t>>'.
how should type decorator takes component takes props , returns component takes props, minus props used wrapper component?
Comments
Post a Comment