I want to use an ES6 React component in another Typescript component.
The ES6 component:
class ModelViewer extends Component {
constructor(props, context) {
super(props, context);
//...
}
// ...
}
export default ModelViewer;
My consuming TS component:
import * as ReactDOM from "react-dom";
import * as React from "react";
import ModelViewer from "./model_viewer/ModelViewer";
export class Viewer extends React.Component<any, any> {
render() {
return (
<div>
<ModelViewer />
</div>
);
}
}
Options for the TSC are:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"removeComments": true,
"sourceMap": true,
"allowJs": true,
"watch": true,
"outDir": "./dist/",
"jsx": "react",
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true
}
}
Now I'm receiving the error TS2605: JSX element type 'ModelViewer' is not a constructor function for JSX elements.
Do I need to provide typings despite having set "allowJS": true
? I've tried different ways to import, but no difference.
App.tsx(11,17): error TS2605: JSX element type 'ModelViewer' is not a constructor function for JSX elements. Property 'setState' is missing in type 'ModelViewer'.
I think TSC doesn't understandextends Component
... tryimport {Component} from "react"
in your ES6 component. – Aaron Beall