我想在另一个 Typescript 组件中使用 ES6 React 组件。
ES6 组件:
class ModelViewer extends Component {
constructor(props, context) {
super(props, context);
//...
}
// ...
}
export default ModelViewer;
我的消费 TS 组件:
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>
);
}
}
TSC 的选项是:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noImplicitAny": false,
"removeComments": true,
"sourceMap": true,
"allowJs": true,
"watch": true,
"outDir": "./dist/",
"jsx": "react",
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true
}
}
现在我收到错误 TS2605: JSX element type 'ModelViewer' is not a constructor function for JSX elements.
尽管设置了,我是否需要提供打字"allowJS": true
?我尝试了不同的导入方式,但没有区别。