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
React: Type inference with ComponentClass results in any #14176
changed the title [-]React: Generic in `ComponentClass` results in `any`[/-][+]React: Type inference with `ComponentClass` results in `any`[/+]on Jan 22, 2017
This issue should be reopened. This bugs currently exists with the latest version of @types/react, and can be reproduced by instantiating the component's constructor. Here's an updated example:
typeProps={foo: string}classFooextendsComponent<Props>{constructor(props){super(props)}render(){return<div/>}}functionfunc<P>(base: React.ComponentClass<P>): React.ComponentClass<P>{returnbase;}// const Bar: React.ComponentClass<any>constBar=func(Foo);
One way to fix this is to make sure to annotate the constructor's argument, i.e.
Activity
[-]React: Generic in `ComponentClass` results in `any`[/-][+]React: Type inference with `ComponentClass` results in `any`[/+]jwbay commentedon Jan 23, 2017
Root cause seems to be way back in #11612. When I remove that constructor from the typings locally, inference sites light up.
Revert 80e4d8b/DefinitelyTyped#11612. Fixes DefinitelyTyped#14176
Merge pull request #14202 from jwbay/react-props-inference
samijaber commentedon Jun 7, 2018
This issue should be reopened. This bugs currently exists with the latest version of
@types/react, and can be reproduced by instantiating the component'sconstructor. Here's an updated example:One way to fix this is to make sure to annotate the
constructor's argument, i.e.This makes
ComponentClass's type inference work correctly.jardakotesovec commentedon Jun 12, 2018
@samijaber Hi, just noticed the same problem. I think it will be necessary to create new issue.. closed issues often not get much attention.