TypeScript Version: 2.9.2
Search Terms: react component props type constructor implicit any hoc
Code
typeRouteComponentProps={history: {};};typeOmit<T,KextendskeyofT>=Pick<T,Exclude<keyofT,K>>;declarefunctionwithRouter<PextendsRouteComponentProps>(component: React.ComponentType<P>,): React.ComponentClass<Omit<P,keyofRouteComponentProps>>;typeFooProps={foo: string}&RouteComponentProps;classFooextendsReact.Component<FooProps>{constructor(props){super(props);}}// Expect error due to missing props, got one :-)consta=<Foo/>;// Expect error due to missing props, got one :-)constb=<Foofoo="1"/>;// However, after using a (correctly defined) HOC, the props type seems to go completelyconstFoo2=withRouter(Foo);// Expect error due to missing props, but got none :-(constc=<Foo2/>;… unless we comment out the constructor, or annotate the props param:
classFooextendsReact.Component<FooProps>{}constFoo2=withRouter(Foo);// Expect error due to missing props, got one :-)constc=<Foo2/>;classFooextendsReact.Component<FooProps>{constructor(props: Props){super(props);}}constFoo2=withRouter(Foo);// Expect error due to missing props, got one :-)constc=<Foo2/>;Why does the presence of the constructor change the props type only after the component is ran through the HOC?
TypeScript Version: 2.9.2
Search Terms: react component props type constructor implicit any hoc
Code
… unless we comment out the constructor, or annotate the
propsparam:Why does the presence of the constructor change the props type only after the component is ran through the HOC?