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
I need to type both stateless component and classic component in single component property:
TypeScript Version:
1.8.10/1.9.0-dev.20160518-1.0
Code
// A self-contained demonstration of the problem follows...// Ideally:interfaceComponentProps{ButtonComponent: React.StatelessComponent<any>|React.ComponentClass<any>;
...
}classMyComponentextendsReact.Component<ComponentProps,{}>{render(){const{ ButtonComponent }=this.props;constsomeProps={};constbutton=<ButtonComponent{...someProps}/>return(<div>{button}</div>);}}// Ideal usage<MyComponentButtonComponent={()=><button>test</button>}/>classMyButtonComponentextendsReact.Component<{},{}>{
...
}<MyComponentButtonComponent={MyButtonComponent}/>
Expected behavior:
Compiles successfully
Actual behavior:
Throws error: "JSX Element type ButtonComponent doesn't have any construct or call signatures"
It works If i change definition of ButtonComponent to just solo React.StatelessComponent or
React.ComponentClass
The text was updated successfully, but these errors were encountered:
StatelessComponent has no construct signature but no call signature. ComponentClass has construct signature but no call signature.
When both types are united, what we get is a type with no construct or call signature.
Whenever a React component is instantiated, first the element instance type will be checked for any construct signatures, then call signatures. (See getJsxElementInstanceType in checker.ts).
One possible fix is to handle union types separately here by recursively checks for construct/call signature.
I need to type both stateless component and classic component in single component property:
TypeScript Version:
1.8.10/1.9.0-dev.20160518-1.0
Code
Expected behavior:
Compiles successfully
Actual behavior:
Throws error: "JSX Element type ButtonComponent doesn't have any construct or call signatures"
It works If i change definition of ButtonComponent to just solo React.StatelessComponent or
React.ComponentClass
The text was updated successfully, but these errors were encountered: